4-character literal

Rick Mann rmann-d-lang at latencyzero.com
Thu Jan 25 22:37:11 PST 2007


Hi. I'm porting some Mac OS X (Carbon) code, and it relies heavily on a language feature that's been used on the Mac for decades: 4-byte character literals (like 'abcd'). In this case, I'm setting up enums that will be passed to OS APIs as 32-bit unsigned int parameters:

enum : uint
{
    kSomeConstantValue = 'abcd'
}

I tried using a 4-character string literal, but I get the following error when I do:

src/d/macos/carbon/carbonevents.d:29: Error: cannot implicitly convert expression ("ptrg") of type char[4] to uint
src/d/macos/carbon/carbonevents.d:29: Error: Integer constant expression expected instead of cast(uint)"ptrg"
src/d/macos/carbon/carbonevents.d:34: Error: cannot implicitly convert expression ("etrg") of type char[4] to uint
src/d/macos/carbon/carbonevents.d:34: Error: Integer constant expression expected instead of cast(uint)"etrg"


I tried basing the enum on dchar, and I tried appending "d" to the end of the string literals, but neither works.

Any suggestions that don't involve significant re-writing of the 4-character literals? Thanks!


P.S. Grr. I don't like posting my unobfuscated email address to public sites.



More information about the Digitalmars-d mailing list