Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site rtp47.UUCP Path: utzoo!linus!decvax!mcnc!rti-sel!rtp47!throopw From: throopw@rtp47.UUCP (Wayne Throop) Newsgroups: net.lang.c Subject: Re: C array follies 1 Message-ID: <179@rtp47.UUCP> Date: Mon, 9-Sep-85 19:59:02 EDT Article-I.D.: rtp47.179 Posted: Mon Sep 9 19:59:02 1985 Date-Received: Thu, 12-Sep-85 23:31:28 EDT References: <171@rtp47.UUCP> <10299@ucbvax.ARPA> Organization: Data General, RTP, NC Lines: 29 > > [Original article questions practice of having sizeof an array > > formal always return pointer size] > ... Are you proposing that C should pass the dimentions of the array > also so a called function can know these things? Or maybe since the > pointer was declared as 'int x[2][2][2];' you want sizeof x to be 8 > ints? I am suggesting that the latter notion is a good idea. In particular, the formal declaration int x[3]; should make sizeof(x) == (sizeof(int) * 3). The formal declaration int *x; should make sizeof(x) == sizeof(int *). The formal declaration int x[]; is a problem. I would prefer it if sizeof(x) yeilded a diagnostic. Failing that, sizeof(x) == sizeof(int *) is next best, I suppose. > I prefer to keep C's ability to pass pointers to arrays or subarrays. So do I. The above suggestion does not affect this. It only affects what happens when sizeof is applied to such a formal name. I dislike the incongruity that in this code fragment void f(x) int x[3]; { int y[3]; ... } sizeof(x) != sizeof(y). This seems like a misfeature to me. -- Wayne Throop at Data General, RTP, NC !mcnc!rti-sel!rtp47!throopw