January 25, 2006 Constant folding for array casts | ||||
---|---|---|---|---|
| ||||
Most casts work at compile time. This particular one does not. (it complains that it's a non-constant expression). ------------- const char[] tapir = "some horned animal"; const byte [] antelope = cast(byte []) tapir; int main() { return 0; } --------------- The next bit of code works, and achieves the same thing -- but not quite at compile time. const char[] tapir = "some horned animal"; const byte [] antelope; static this() { antelope = cast(byte []) tapir; } |
February 04, 2006 Re: Constant folding for array casts | ||||
---|---|---|---|---|
| ||||
Posted in reply to Don Clugston Attachments: | Don Clugston schrieb am 2006-01-25: > Most casts work at compile time. This particular one does not. (it complains that it's a non-constant expression). > ------------- > const char[] tapir = "some horned animal"; > > const byte [] antelope = cast(byte []) tapir; > > int main() { return 0; } > --------------- > > The next bit of code works, and achieves the same thing -- but not quite at compile time. > > const char[] tapir = "some horned animal"; > > const byte [] antelope; > static this() > { > antelope = cast(byte []) tapir; > } Added to DStress as http://dstress.kuehne.cn/run/c/cast_31_A.d http://dstress.kuehne.cn/run/c/cast_31_B.d Thomas |
Copyright © 1999-2021 by the D Language Foundation