Xref: utzoo comp.lang.c:20019 comp.bugs.4bsd:1343 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!unido!sbsvax!greim From: greim@sbsvax.UUCP (Michael Greim) Newsgroups: comp.lang.c,comp.bugs.4bsd Subject: Is this a bug in some C compilers? Keywords: bug; cc; referencing a pointer as if it were a structure Message-ID: <800@sbsvax.UUCP> Date: 19 Jul 89 09:58:53 GMT Followup-To: comp.lang.c Organization: Universitaet des Saarlandes, Saarbruecken, W-Germany Lines: 72 Hello, I tried the following program on several machines. IMHO the program should not compile yet there are some compilers which compile it: cc 43bsd cc 43bsd-tahoe cc ultrix 2.0 cc SunOS 3.5 And there are some that give an error message: gcc 1.34 cc sinix 2.1 ("McClure") Here is the program: ---------- cut here ---------------------------- /* * What does the compiler do with this? */ # include struct link { struct link * next; int count; }; int fix0; struct link * t; int fix1; main () { printf ("t lies at %1d, brk is at %1d\n", (int)(&t), (int)sbrk(0)); printf ("Addresses of %1d byte objects around t : %1d and %1d\n", sizeof(int), (int)(&fix0), (int)(&fix1)); t = NULL; t.count = 5; if (t.count == 5) printf ("Assignment worked.\n"); else printf ("Assignment did not work\n"); printf ("Value 5 has been put at address %1d\n", &(t.count)); } ---------- cut here ---------------------------- Output from VAX running 43bsd: Script started on Wed Jul 19 11:44:22 1989 % cc test78.c "test78.c", line 21: warning: struct/union or struct/union pointer required "test78.c", line 22: warning: struct/union or struct/union pointer required "test78.c", line 26: warning: struct/union or struct/union pointer required % a.out t lies at 6008, brk is at 6176 Addresses of 4 byte objects around t : 6004 and 6012 Assignment worked. Value 5 has been put at address 6012 % exit % script done on Wed Jul 19 11:44:47 1989 Am I correct to say that the program is not correct C, and that all compilers which compile it are wrong? -mg -- Michael Greim Email : greim@sbsvax.informatik.uni-saarland.dbp.de or : ...!uunet!unido!sbsvax!greim [.signature removed by the board of censors for electronic mail's main executive computer because it contained a four letter word ("word")]