Ioannis Vranos said:
I am talking about C90/C95.
As opposed to C99, I presume? I see nothing in this thread that's
C99-specific.
Keith said:
int ar[8]= {1, 2, 3, 4, 5, 6, 7, 8};
Given the initializer, the size needn't be specified.
And?
int ar[8]= {1, 2, 3, 4, 5, 6, 7, 8};
On the other hand, if you get the size wrong the compiler will
complain; that might be the point.
It isn't bad practice to specify the size of an array explicitly,
under any circumstances, and of course one may not specify it
explicitly and depend on the initializer.
So there was no point for making these comments.
I'll grant you that there wasn't *much* of a point, but there was some.
If you declare the array as:
int ar[] = {1, 2, 3, 4, 5, 6, 7, 8};
then you don't have to update the size constant when you add new
elements to the array:
int ar[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Incidentally this was in the original code, which you copied; I wasn't
criticizing you, just commenting on the code.
const size_t SIZE= sizeof(ar)/sizeof(ar[0]); /* this gets 8 perfectly */
The parentheses are unnecessary but harmless. All-caps identifiers
are conventionally used for macros, but using one for a constant isn't
too bad.
There was no point for this comment too.
The point is that the parentheses are unnecessary but harmless, and
that all-caps identifiers are ... well, see above. Personally, I
prefer not to use parentheses on a sizeof operator unless they're
necessary. It emphasizes the important point that sizeof an an
operator, not a function. I don't object to the extra parentheses;
I'm just pointing out that they're not needed.
The spaces thing in my quoted code must be a bug of my newsgroup
program, my first post with the redundant #include <stddef.h> had
spaces placed well.
Were you using tab characters, perhaps without knowing it?