Constant declarations for mac OSX

Thomas Kuehne thomas-dloop at kuehne.cn
Thu Feb 23 08:26:21 PST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gareth Baker schrieb am 2006-02-23:
> I'm running GDC on mac OSX. The mac tags events with a four character code which
> is converted to a 
> UInt32 along the lines of:
>
> (s[0] << 24) || (s[1] << 16) || (s[2] << 8) || (s[3])
>
> where s[n] is the ascii charater number.
>
> I need to declare:
>
> const OSType    kEventClassCommand            = FOUR_CHAR_CODE("cmds");
>
> Browsing the documentation seems to indicate I need a template but I can't seem
> to work out how. Can 
> anybody help?


| template FOUR_CHAR_CODE(char[] cmd){
|     static if(cmd.length != 4){
|         pragma(msg, "require 4 chars");
|         static assert(0);
|     }else{
|         const uint FOUR_CHAR_CODE = (cmd[0] << 24) | (cmd[1] << 16) | (cmd[2] << 8) | cmd[3];
|     }
| }

...

| const OSType    kEventClassCommand = FOUR_CHAR_CODE!("cmds");

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFD/e/73w+/yD4P9tIRAmxyAJ96Kr/16xTztRgsQryIl+AESM/K5wCbBLqB
5PCfgZCLXC0RS4rXVw4IGSg=
=2eJL
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-learn mailing list