[Bug 18] New: int foo[0] accept -- what's its semantics?
Chris Miller
chris at dprogramming.com
Sun Mar 5 17:03:17 PST 2006
> void main() {
> int foo[0];
> }
>
> dmd 0.148 accepts this gdc 0.17 and my 0.18 work in progress both segv
> off in
> gcc land where it's assumed that variables passed into the middle end
> all have
> space associated with them. What are the right semantics for this
> situation?
I'd like it to be allowed and completely disable bounds checking on that
array, so that the old C trick can work: putting an array as the last
field in a struct so that extra memory can be allocated after the struct
to add more elements to the array at runtime. To further support this,
'new' for structs could be overloaded to take a parameter specifying how
many elements are to be allocated for that last array field, for example:
struct Foo
{
char* bar; // GC should know about this.
int[0] baz; // Actual number of elements specified in new().
}
...
Foo* f = new(3) Foo; // Allocates 3 ints for Foo.baz for this instance.
More information about the Digitalmars-d-bugs
mailing list