It was posted on this site how you could generate unique enum constants by doing the following:
enum _EXAMPLE
{
LEFT = 'left',
RIGHT = 'right'
//etc
};
Ignoring the issue of validity, how are the numbers generated? More specifically, what technique is used? As I wish to try to build a function that emulates it for short strings.
'left'is a multicharacter literal (2.13.2/1 of C++03), it has typeint.It’s implementation-defined what integer value it actually has. In particular, there’s no guarantee that
'left'and'right'aren’t equal, so you’re on to something of a loser using them in an enum.For an example, though, GCC documents its behavior here: http://gcc.gnu.org/onlinedocs/gcc-4.6.1/cpp/Implementation_002ddefined-behavior.html#Implementation_002ddefined-behavior
'right'has five characters, and clearly it’s not possible for every 5-character string to have a different 32 bit value.