[oclug] time for my weekly dumb question -> C and memory
Gilles J. Seguin
segg at infonet.ca
Wed Apr 4 15:55:03 EDT 2001
"Brenda J. Butler" wrote:
>
> Hmm, I suppose compilers on architectures with different
> alignment requirements might do different things with the
> structs at each end, esp if the structs were structured
> like this:
Also see "Using and porting GNU CC"
paragraph 6.26 Inquiring on Aligment of Types or Variables
paragraph 6.27 Specifying Atributes of Variables
This is not the way to specify intended behavior,
but is the C syntax for implementing aggregate.
i.e.: float is a good example where problems can occur
with different platform.
Source code is not a good specification, but a representation
of the intended behavior.
thing_one:= allowed value are [0..254] or is it [-124..+124],
do we implement char or unsigned char.
thing_two:= idem
thing_three:= idem
Thing_four:= you must define allowed range for mantissa and exponent.
> struct oops {
> char thing_one;
> long thing_two;
/* thing_two follows thing_one */
long thing_two __attribute ((packed));
> char thing_three;
/* changed default alignment, have no effect here
we need to add a [unsigned] char member to see effect */
char thing_three __attribute ((aligned(2)));
> float thing_four;
float thing_four __attribute ((packed));
> };
> There might be different-sized padding between thing_one
> and thing_two on different architectures (because thing_two
> might require 32 bit alignment on one architecture and 64
> bit alignment on the other).
>
> Hmm. Live and learn. Anything else?
More information about the OCLUG
mailing list