Just don't try to use pointers as enumeration constants. Its a bad idea - loss of enumeration type safety, hard to serialize, hard (as you have seen) to enforce the behaviour you need with different compilers, hard for other programmers to understand etc etc.
I totally fail to see why "red" is better than Color::red by the way. I can see reasons why Color::red is better than "red" though:
void f(Color::Type type);
void g(const char *type);
f() you can't accidentally pass a wrong type to. g() you can pass anything to. Its just abuse of the compiler and silly.
Yes, if you can guarantee that all of the identical strings are merged and all reside at the same address, this can work. That doesn't make it something you should do.
I was verry hapyy with that : you just passes string litereals everything
works and is top efficient end easy expandable, errors and mistakes
are also very easy to cactch here
void f(char* str)
{
if(str=="red") ;
else if(str=="green") ;
else if(str=="orange") ;
else ERROR("string %s unrecognized in ...", s);
}
(thats why i am emphasizing this is my invention, (though maybe someone was used before but i never heard of it) (well two inventions really, one is a concept of "ad-hoc" enum that was first , and second is its string literal implementation) because i was so happy with that
the practical reason of its great usability is the thing that you
spare code jumping (to definition - which is tiring really),
also you do not need to maintain this enums definitions stuff
but aprat of this - i got a bit of breadown because this -fmerge-constants do not work across the modules (so i cannot use this technique across the modules) and i dont know why it does not work, and how to make it work - could someone help yet? (tnx kingmir for hint it was usefull)