www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit alloca for static arrays

reply "Lionello Lunesu" <lio remove.lunesu.com> writes:
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
Mar 23 2006
parent "Craig Black" <cblack ara.com> writes:
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

 

Mar 23 2006