C/C++ enum and char * array

Posted by Eric M on Stack Overflow See other posts from Stack Overflow or by Eric M
Published on 2011-02-08T15:12:54Z Indexed on 2011/02/08 15:25 UTC
Read the original article Hit count: 248

Filed under:
|
|
|

Ran accross the following code in an article and didn't think it was standard C/C++ syntax for the char* array. As a test, both Visual C++ (visual studio 2005) and C++ Builder Rad XE both reject the 2nd line.

Without using #defines, anyone have any tricks/tips for keeping enums and a string array sort of in sync without resorting to STL ?

More of a curiosity question.

enum TCOLOR { RED, GREEN, BLUE };

char *TNCOLOR[] = { [RED]="Red", [GREEN]="Green", [BLUE]="Blue" };

as an aside, the article this came from is quite old and I believe this might work under GCC but have not tested.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c