Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!xanth!byrum From: byrum@cs.odu.edu (Terry Franklin Byrum) Newsgroups: comp.lang.c Subject: Re: Character constants Summary: sizeof test program... Keywords: NULL Message-ID: <8002@xanth.cs.odu.edu> Date: 7 Mar 89 15:47:28 GMT References: <13068@steinmetz.ge.com> <102@servio.UUCP> <7447@pyr.gatech.EDU> Organization: Old Dominion University, Norfolk, Va. Lines: 57 I am borrowing this account; see signature below. Speaking of checking sizeof() to determine language specifications, I've found it to be of even greater use in revealing compiler aberrations (BUGS!!). Try the following little program on your "favorite" compiler. Explaining each line is a good exercise for the novice, and loooking at the output is a good test of a compiler. Notice that the Microsoft compiler gets line 2 correct, but blows line 3: incredible since it is a fundamental rule of C language that p[i] == *(p + i) for any pointer p and int i. With attitudes like that, it's a wonder it ever gets any array indexing or pointer indirection right! Lloyd Kremer Brooks Financial Systems ...!xanth!brooks!lloyd Have terminal ... will hack! ------------------cut here------------------------------------------ main() { double foo[2][10]; printf("sizeof(foo) == %d\n", sizeof(foo)); printf("sizeof(foo[0]) == %d\n", sizeof(foo[0])); printf("sizeof(*foo) == %d\n", sizeof(*foo)); printf("sizeof(foo[0][0]) == %d\n", sizeof(foo[0][0])); printf("sizeof(**foo) == %d\n", sizeof(**foo)); printf("sizeof(*foo[0]) == %d\n", sizeof(*foo[0])); printf("sizeof((*foo)[0]) == %d\n", sizeof((*foo)[0])); return(0); } /* CORRECT OUTPUT: (assuming sizeof(double) == 8) sizeof(foo) == 160 sizeof(foo[0]) == 80 sizeof(*foo) == 80 Microsoft 5.1 C Compiler says 160 here! (BROKEN!!) sizeof(foo[0][0]) == 8 sizeof(**foo) == 8 sizeof(*foo[0]) == 8 sizeof((*foo)[0]) == 8 */ ------------------cut here------------------------------------------ -- Inventions have long since reached their limit -- and I see no hope for further developments. - Julius Frontinus, world famous engineer, Rome, 10 AD | Terry Franklin (Frank) Byrum | BROOKS Financial Systems, Inc. ___ | INET: byrum@cs.odu.edu /__ _. __. _ _ /_ | UUCP: ...!sun!xanth!brooks!byrum / _/ \_(_/|_|\|_/ \ | DISCLAIMER: No one listens anyway!