Welcome, Guest. Please login or register.

Author Topic: multi-character character constants in C++  (Read 5191 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show all replies
    • http://www.iki.fi/sintonen/
Re: multi-character character constants in C++
« on: April 05, 2003, 10:28:26 PM »
Your code makes an assumptation that int is 32bit. If you can live with this assumptation, then:

#define mkid(a,b,c,d) ((a)<<24 | (b)<<16 | (c)<<8 | (d))

enum
{

JOHN_NAME = mkid('j','o','h','n'),
FRED_NAME = mkid('f','r','e','d'),
...

};

However, one can wonder if this makes any sense at all. Why not just have indexes from 0...n instead?

You can have the names as strings in another indexed table.