[lug] OFF: sizeof structs in gcc?

Tkil tkil at scrye.com
Thu Jun 7 14:17:23 MDT 2001

>>>>> "Tkil" == Tkil  <tkil at scrye.com> writes:

Tkil> it usually prefers the fastest allocation for the given
Tkil> platform, which is usually at least 4 bytes (e.g. doubles might
Tkil> be faster on 8-byte boundaries)

i apologize for that paragraph.  i was smoking something bad,
obviously.  there are some grains of truth, but i managed to confuse

for some processors, memory values must be aligned on boundaries that
are a multiple of the data size -- so a 4-byte int would be on a
4-byte boundary, an 8-byte double or long long on an 8-byte boundary,
etc.  so, doing any work with a non-aligned value implies doing two
reads, reconstructing the value in a register, manipulating it, then
doing two writes.

so, when i said "fastest" in my original paragraph, i was referring to
execution speed.  using the "packed" attribute (or pragma, however you
get there) is usually a space/time tradeoff, although another common
use is to make c structures map directly onto a hardware or media data

for some discussion on this topic, please see the C FAQ, questions
2.12 through 2.15 inclusive:



More information about the LUG mailing list