[lkml]   [2000]   [Oct]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: On labelled initialisers, gcc- and tcp_ipv4.c
On Sun, 15 Oct 2000, Andrew Morton wrote:

> There is a bug in gcc- It incorrectly lays out
> structure initialisers when the `name:value;' construct is used.
> Here is the degenerate case:
> struct struct_1 { int a; };
> struct thing {
> int a;
> struct struct_1 b;
> };
> struct thing a_thing = {
> // a: 0, /* Uncomment this for correct code */
> b: {0},
> };
> Which produces:
> .file "e.c"
> .version "01.01"
> gcc2_compiled.:
> .globl a_thing
> .data
> .align 4
> .type a_thing,@object
> .size a_thing,8
> a_thing:
> .zero 4
> .zero 4
> .long 0
> .ident "GCC: (GNU)"
> Note the extra `.zero 4'.
> 3: Don't use gcc- (use one of the later compilers and
> put up with 50% longer build times).
> 4: Fix gcc-

The 'C' language can order structure members anyway it wants. It also
can add any 'fill' or alignment bytes it wants. The compiler is not
broken in this respect.

If the structure must exist in memory exactly as you have
coded it (i.e., a template), then you have to use some 'extentions'
that are not part of the 'C' language, but are often provided
by the compiler(s), __attribute__ ((PACKED)), comes to mind.

When using bit-fields, the same is true. This is why you never
use bit-fields to access hardware. Instead you use machine-specific
unsigned shorts, ints, longs, etc.

Truly 'portable' stuff, like network-sync-crash programs, use
character arrays to generate network packets. It is not allowed
for a 'C' compiler to introduce extraneous characters within such
an array or at its beginning. However, it can append anything it
wants, i.e., fill up to the next machine-specific alignment.

Dick Johnson

Penguin : Linux version 2.2.17 on an i686 machine (801.18 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 12:41    [W:0.117 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site