Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!brl-adm!adm!escott%deis.uci.edu@icsg.uci.edu From: escott%deis.uci.edu@icsg.uci.edu Newsgroups: comp.lang.c Subject: Auto variable with sizeof == 0 Message-ID: <4114@brl-adm.ARPA> Date: Thu, 29-Jan-87 23:37:52 EST Article-I.D.: brl-adm.4114 Posted: Thu Jan 29 23:37:52 1987 Date-Received: Sat, 31-Jan-87 02:20:28 EST Sender: news@brl-adm.ARPA Lines: 34 Somebody recently came to me with a program that worked on a VAX 11/750 running 4.2BSD but failed on our Sequent Balance 21000 running Dynix 2.1. The apparent culprit was of course the C compiler on the latter machine. However, after examining the code in question, I found a construct that seems a little strange to me: an automatic variable was declared as a "struct foo **bar[]". "How could this be right?" I said to myself. "How can you declare an automatic variable that has no size?" So I wrote a program that contained a similar declaration, and then tried to take sizeof( bar ). Sure enough: warning: sizeof returns 0 [This from the VAX 11/750 4.2BSD compiler] Okay, that makes sense. My question is: is there any reason why you should be able to declare an array with zero elements as an automatic variable? What's strange is that, on the VAX, the program apparently successfully dereferenced bar, both setting a value for "*bar" and then using that value later. How can this be right? How can "bar" have any value at all, much less "*bar"? If there is no use for a zero-sized automatic variable, how come the compiler lets you do it? (Even a C compiler should occasionally clamp down 8^). And, just for the heck of asking, does ANSI C let you make such a declaration? +-------------------------------------------------------------------------+ Scott Menter UCI ICS Computing Support Group Univ. of Calif. at Irvine (714) 856 7552 Irvine, California 92717 Internet: escott@ics.uci.edu UUCP: ...!ucbvax!ucivax!escott Bitnet: escott@uci CSNet: escott%ics.uci.edu@csnet-relay Internet (with Name Server): TBA +-------------------------------------------------------------------------+