[scribus] a development question on initializing ItemMultipleDuplicateData

Václav Šmilauer eu at doxos.eu
Fri Sep 14 10:51:15 UTC 2018

Although I am not the adressee of the question, mu 2/100€:
memset to zero makes only sense on POD-types (c-compatible layout).
Those have trivial copy-assignment (bitwise-copyable). String is not a
POD type (unlike char*), as it contains opaque internal data (like
length, pointer to the buffer, maybe more) and thus setting it to 0
will not do anything useful.
> my question: can i replace the two lines above with:
> ItemMultipleDuplicateData mdData{};
No. Unless you provide default constructor which will set to zero all
POD-types contained in the struct (non-POD types like strings will be
initialized using their default ctors), and then you can omit the "{}"
as well (If you upgraded to c++11, you can put (POD and non-POD)
initilizers inline). In that case, you can also delete the memset(...)
because that will have been done by the ctor already. 

Like this:

struct ItemMultipleDuplicateData
        // default ctor
	int type;
	int copyCount;
	int copyShiftOrGap;
	double copyShiftGapH;
	double copyShiftGapV;
	double copyRotation;
	int gridRows;
	int gridCols;
	double gridGapH;
	double gridGapV;

or like this (c++11):

struct ItemMultipleDuplicateData{	int type=0;	int
copyCount=0;	int copyShiftOrGap=0;	double
copyShiftGapH=0.;	double copyShiftGapV=0.;	double
copyRotation=0.;	int gridRows=0;	int gridCols=0;	d
ouble gridGapH=0.;	double gridGapV=0.;};

Cheers, v.

> hi jean and craig
> i have a question to you:
> in scribusMainWindow::duplicateItem() mdData isinitialized through a
> memset():
> ItemMultipleDuplicateData mdData;memset(&mdData, 0, sizeof(mdData));
> https://github.com/scribusproject/scribus/blob/master/scribus/scribus
> .cpp#L6431
> on the one side, usertaskstructs.h does not seem to be
> explicitlyimported which is a bit odd to me.
> on the other side, for the extension to multiple duplicate
> i'veprogrammed (and which i will present very soon: yeah!) i needed
> to adda string to ItemMultipleDuplicateData and now memset() does not
> work anymore and gives me the error:
> /home/ale/src/scribus-github/scribus/scribus.cpp: In member
> function‘void Scri
> busMainWindow::duplicateItem()’:/home/ale/src/scribus-
> github/scribus/scribus.cpp:6438:35: warning:‘void* memse t(void*,
> int, size_t)’ clearing an object of type ‘structItemMultipleDuplicate
> Data’ with no trivial copy-assignment; useassignment or value-
> initialization i nstead [-Wclass-memaccess]  memset(&mdData, 0,
> sizeof(mdData));
> ?
> in my eyes, it does the same... but i don't know much about
> memset()...
> ciaoa.l.e
> ___Scribus Mailing List: scribus at lists.scribus.netEdit your options
> or unsubscribe:http://lists.scribus.net/mailman/listinfo/scribusSee
> also:http://wiki.scribus.nethttp://forums.scribus.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scribus.net/pipermail/scribus/attachments/20180914/6f380a74/attachment.html>

More information about the scribus mailing list