Menu

Automatic Enum Handling in C — Parsing, Validating and Iterating.
🖼️

Automatic Enum Handling in C — Parsing, Validating and Iterating.

DEV Community·Yair Lenga·6 months ago
#zj5FYdwc
#coding#programming#systems#software#enum
Reading 0:00
15s threshold

In a previous post, Automatic Enum Stringification in C via Build-Time Code Generation , I described how to extract enum labels and values directly from DWARF debug information at build time.

enum color { C_NONE , C_RED , C_YELLOW , C_GREEN } ;

// Request enum descriptor for e_color ENUM_DESCRIBE ( e_color , enum color ) void foo ( enum color c ) { printf ( "Color=%s(%d) \n " , ENUM_LABEL_OF ( e_color , c ), c ) ; }

Enter fullscreen mode

Exit fullscreen mode

In a follow-up article, I wrote about the next logical step: reverse conversion from symbolic name to value.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.