Possible to convert list of #defines into strings

前端 未结 8 1112
梦谈多话
梦谈多话 2021-02-05 22:45

Suppose I have a list of #defines in a header file for an external library. These #defines represent error codes returned from functions. I want to wri

8条回答
  •  情话喂你
    2021-02-05 23:14

    I normally do it the giant switch case way, although I make it somewhat easier with:

    #define STR(code) case code: return #code
    switch (errorCode)
    {
        STR(NO_ERROR);
        STR(ONE_KIND_OF_ERROR);
    }
    

    This is a good question, I'm interested to see what better ways people have

提交回复
热议问题