C array follies 1
Wayne Throop
throopw at rtp47.UUCP
Tue Sep 10 09:59:02 AEST 1985
> > [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
<the-known-world>!mcnc!rti-sel!rtp47!throopw
More information about the Comp.lang.c
mailing list