4-character literal

torhu fake at address.dude
Thu Jan 25 23:32:17 PST 2007


torhu wrote:
> Rick Mann wrote:
>> Rick Mann Wrote:
>> 
>>> enum : uint
>>> {
>>>     kSomeConstantValue = 'abcd'
>>> }
>> 
>> 
>> I realized I was misunderstanding something else I saw, and that "abcd"d doesn't do what I thought (make a 4-byte character).
>> 
>> So: how to I do the equivalent of 'abcd'?
>> 
>> Thanks!
> 
> Try this.
> 
> template MAKE_ID(char[] s)
> {
>      static assert(s.length == 4);
>      const uint ID = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
> }
> 
> enum : uint
> {
>      kSomeConstantValue = MAKE_ID!("abcd")
> }

Seems I was too quick.  Replace 'const uint ID' with 'const uint 
MAKE_ID', and it will compile.



More information about the Digitalmars-d mailing list