Is this a bug in some C compilers?

john.j.tupper maddog at cbnews.ATT.COM
Thu Jul 20 07:07:49 AEST 1989


In article <800 at sbsvax.UUCP> greim at sbsvax.UUCP (Michael Greim) writes:
>	printf ("Value 5 has been put at address %1d\n", &(t.count));
> ....
>Am I correct to say that the program is not correct C, and that all compilers
>which compile it are wrong?

Michael is complaining about the fact he got away with writing t.count when
t was a pointer (the compiler should have insisted on t->count).

K&R C treats member names as offsets. I.e. fred.foo turns into
*(&fred + offset_to_foo). What's more (this is the braindamaged part) member
names are global across all structures. This means the following is correct:

struct a {
	int a_mem;
};

struct b {
	int b_mem;
} one_b;

one_b.a_mem = 0;

As illistrated by Michael's example, the variable you take a member of doesn't
even have to be a structure at all!

K&R don't actually  and say this, but they do allude to it. On page 197,
paragraph 5, it says that two structures may have the same member name
it the member is the same type and at the same offset in both structs.

Some C compilers retain this bogisity, some fixed it.
--------------------------------------------------------------
sdfl sdf sldkf sdlfoi			My real signature is illegible too.



More information about the Comp.lang.c mailing list