array of elements of various sybtypes
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Jan 26 20:40:39 PST 2011
On 1/27/11, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> I'm not sure why this works and the other doesn't, but we
> definitely need something that allows one to control the array type of a
> literal.
pragma helps in discovering what DMD does sometime. This will error
out but it will give some useful info:
pragma(msg, typeid( [1,2,cast(ubyte)3] ));
error: [1,2,cast(int)cast(ubyte)3] , &D11TypeInfo_Ai6__initZ
So it forces a cast back to int again.
But we can use a postfix to set an unsigned type for the whole array:
writeln(typeid( [1,2,3u] )); // uint[]
And we can select a string type with a postfix, but we can't use a cast:
void main()
{
writeln(typeid( ["a"d, "b", "c"] )); // works
writeln(typeid( [cast(dchar)"a", "b", "c"] )); // doesn't work,
// Error: incompatible types for ((cast(dchar)"a") ? ("b")): 'dchar'
and 'string'
}
More information about the Digitalmars-d-learn
mailing list