TIL

Converting Enums to String in C

I found a clever way to convert enums to strings while working on a project involving QuickJS, a lightweight JavaScript engine. The QuickJS VM uses enums to define its bytecodes, and I needed to convert these enums into strings for debugging and decompilation purposes. Problem In Quick Js, Enums for bytecodes were defined like this typedef enum { OP_invalid, OP_push_i32, OP_push_const } OPCodeEnum; And I needed to convert this to string.