digitalmars.D.learn - Constant declarations for mac OSX
- Gareth Baker (13/13) Feb 23 2006 I'm running GDC on mac OSX. The mac tags events with a four character co...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (7/14) Feb 23 2006 Not what you want (since it isn't automatic), but I used:
- Oskar Linde (10/21) Feb 23 2006 template FourCharCode(char[] s) {
- Thomas Kuehne (19/29) Feb 23 2006 -----BEGIN PGP SIGNED MESSAGE-----
- g.j.baker dl.ac.uk (3/3) Feb 23 2006 Thanks for the answers. I'll give them a go tonight.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (3/11) Feb 23 2006 Seems to do the trick. (returns 0x636d6473)
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? Thanks Gareth Baker g.j.baker at dl.ac.uk
Feb 23 2006
Gareth Baker wrote: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?Not what you want (since it isn't automatic), but I used: 0000000 636d 6473 0a00 0000005 Which means that the value of your constant is 0x636d6473 --anders
Feb 23 2006
Gareth Baker wrote: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");template FourCharCode(char[] s) { static assert(s.length == 4); const uint FourCharCode = (s[0]<<24)|(s[1]<<16)|(s[2]<<8)|(s[3]); } int main() { writefln("%x",FourCharCode!("cmds")); return 0; } /Oskar
Feb 23 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-----
Feb 23 2006
Thanks for the answers. I'll give them a go tonight. Gareth Baker g.j.baker at dl.ac.uk
Feb 23 2006
Thomas Kuehne wrote:| 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]; | } | }Seems to do the trick. (returns 0x636d6473) --anders
Feb 23 2006