Minor issue - zero-length fixed size arrays in variable-sized structs..
Jarrett Billingsley
jarrett.billingsley at gmail.com
Wed Jul 8 15:55:37 PDT 2009
I noticed in the spec on arrays that "A [fixed-size] array with a
dimension of 0 is allowed, but no space is allocated for it. It's
useful as the last member of a variable length struct.." This sounds
like C99's "flexible array members," where a struct can have an array
as its last element that isn't given a size, specifically for allowing
variable-sized structs.
Well, the issue with a zero-length fixed-size array is that.. uh, you
can't access anything out of it. The compiler disallows any indexing
of a zero-length array with constant indices, and at runtime, all
accesses caught by the array bounds checking. Weirder still, the .ptr
of any zero-length array is always null, so you can't even do things
like "arr.ptr[5] = x;" (which would be perfectly acceptable in my
opinion).
Just a silly issue.
More information about the Digitalmars-d
mailing list