Date: Fri, 10 Jun 2005 14:53:40 +0300 From: Giorgos Keramidas <keramida@freebsd.org> To: Ruslan Ermilov <ru@freebsd.org> Cc: Dag-Erling Sm?rgrav <des@des.no>, freebsd-current@freebsd.org Subject: Re: [current tinderbox] failure on ...all... Message-ID: <20050610115340.GA81777@orion.daedalusnetworks.priv> In-Reply-To: <20050610110254.GB79872@ip.net.ua> References: <84dead720506091950779d1661@mail.gmail.com> <86oeae3d8f.fsf@xps.des.no> <84dead72050610001675a32c19@mail.gmail.com> <863brq3bbz.fsf@xps.des.no> <84dead7205061001534b9385b3@mail.gmail.com> <863brqy41j.fsf@xps.des.no> <20050610091624.GA35628@wombat.fafoe.narf.at> <20050610094615.GC79474@ip.net.ua> <20050610102813.GA81548@orion.daedalusnetworks.priv> <20050610110254.GB79872@ip.net.ua>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-06-10 14:02, Ruslan Ermilov <ru@freebsd.org> wrote: >On Fri, Jun 10, 2005 at 01:28:13PM +0300, Giorgos Keramidas wrote: >> That would be very hard to guarantee if two different modules that use >> the types are compiled with different alignment options, right? >> >> /* header1.h */ >> struct t1 {short t1s; int t1a;}; >> >> /* header2.h */ >> struct t2 {short t2s; int t2a;}; >> >> /* module1.c */ >> #include "header1.h" >> struct t1 x; >> >> /* module2.c */ >> #include "header1.h" >> #include "header2.h" >> extern struct t1 x; >> struct t2 y; >> >> If the two modules are compiled with different options that may affect >> struct member alignment, how would one ensure that it is correct to >> use code like this in module.c? >> >> y.t2s = 10; >> y.t2a = 100; >> memcpy(&x, &y, sizeof(x)); >> >> Even the use of sizeof(x) is tricky here, since there is no guarantee >> that sizeof(x) < sizeof(y). > > And if both modules use the same t1 but compiled with different alignment > options, the memcpy() in module.c won't work either, even a simple assignment > could break. :-) Probably no. Two struct t1 objects have the same type and assignment between the two may be implemented as "element-at-a-time memcpy)", as mentioned in $6.2.6.1(6) and footnote (42) of the C99 standard. This may or may not break though, but I couldn't find any good reference to it.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050610115340.GA81777>