4-character literal

Gregor Richards Richards at codu.org
Thu Jan 25 23:28:50 PST 2007


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!

Two solutions come to mind:

1) Will work, very ugly:
(cast(uint) 'a' << 24) + (cast(uint) 'b' << 16) + (cast(uint) 'c' << 8) 
+ cast(uint) 'd'

2) Probably won't work:
*(cast(uint*) ("abcd".ptr))

3) Will work:
0x61626364

Each pretty bad. IMHO the original solution is pretty bad too :)

  - Gregor Richards



More information about the Digitalmars-d mailing list