March 23, 2006 Implicit alloca for static arrays | ||||
---|---|---|---|---|
| ||||
If you'd ask me, this should definately be included before 1.0: # void somefunc( uint i ) { # char[i] array; // creates static array but with run-time length (*) # } This can currently be done by using alloca (for the record:) # import std.c.stdlib; # void somefunc( uint i ) { # char[] array = (cast(char*)alloca(char.sizeof * i))[0..i]; # } which works fine, as long as you don't append / resize the array. L. (*) this code generates 4 identical compiler errors: Integer constant expression expected instead of (events).length |
March 23, 2006 Re: Implicit alloca for static arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lionello Lunesu | Agreed. Stack arrays are useful for efficiency reasons. It doesn't seem like it would be hard for Walter to implement. -Craig "Lionello Lunesu" <lio@remove.lunesu.com> wrote in message news:dvuf4v$1dra$1@digitaldaemon.com... > If you'd ask me, this should definately be included before 1.0: > > # void somefunc( uint i ) { > # char[i] array; // creates static array but with run-time length (*) > # } > > This can currently be done by using alloca (for the record:) > > # import std.c.stdlib; > # void somefunc( uint i ) { > # char[] array = (cast(char*)alloca(char.sizeof * i))[0..i]; > # } > > which works fine, as long as you don't append / resize the array. > > L. > > (*) this code generates 4 identical compiler errors: > Integer constant expression expected instead of (events).length > > |
Copyright © 1999-2021 by the D Language Foundation