Jurij Smakov napsal(a):
On Sun, Sep 24, 2006 at 10:06:51PM +0200, Daniel Smolik wrote:
Hi,
when I compile eeprom.c with gcc-3.3 works without fix. May be this isn't
problem in eeprom.c but in gcc or gcc usage. What do you mean ?
Hi Daniel,
The fix works because once you declare something as int, compiler *has* to align
it at a 4-byte boundary, if it would not do that, that would be a bug. For a char
array there is probably no alignment requirement, so it's perfectly ok for it to
be unaligned. The fact that you do not see the same behaviour with gcc-3.3 is not
surprising either: depending on the implemented optimizations different compilers
may use different layouts of variables in memory, so in some cases buf2 may be
aligned. Note that compiling eeprom.c with gcc-4.1 and -O0 instead of -O2 also
does not trigger the bug.
You can force alignment of variables in gcc using the alignment attribute, for
example writing something like
char foo __attribute__ ((aligned(4)));
should cause foo to be aligned on a 4-byte boundary. Hm, it's confusing,
because I
think I tried this before on buf2 and it did not work (got a gcc warning about
ignored attribute, maybe I did not spell it correctly?). Now it appears to work
though :-/. I guess I need to rework my solution to use this instead.
Best regards,
I test modification with __attribute__ and it works OK with latest Debian
upgrades gcc compile this without warnings and eeprom works. I mean that this
solution is much cleaner that your previous.
Thanks
Dan Smolik
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]