Zero Length Arrays Allowed in C Standard?
Triantaphyllos Byron Rakitzis
tbrakitz at phoenix.Princeton.EDU
Wed Dec 6 06:52:09 AEST 1989
Bill Wells says:
>This still can waste memory, because of padding in the size of
>SYMTAB. Moreover, some systems might take that [1] declaration
>seriously and give you an error when you access something beyond
>the first element of the string. The kind that immediately comes
>to mind is debugging interpreters: these, one hopes, will check
>for accessing outside the bounds of an array.
Wait, hold on a second. If an implementation of C does bounds checking
then it isn't C any more. That's not how C works. There's no such
thing as an array in C. Just pointers, and memory. It's up to the
system to do segementation protection, if it wants.
Byron Rakitzis
(Honestly, I don't see any problem with declaring an array [1] and
then subtracting one from the malloc() call. Really, what's the
problem? How can this be a waste of memory? You never have a zero-byte
string! C strings are always terminated with a '\0' anyway!!)
--
"C Code."
"C Code run."
"Run, Code, run!"
Byron Rakitzis. (tbrakitz at phoenix.princeton.edu ---- tbrakitz at pucc.bitnet)
More information about the Comp.lang.c
mailing list