Skip to main content

Posts

printing enum as string

While coding C programming, there will be scenarios where you want to print the enum values as string while debugging. There are methods where you can define separate function which will return the string of definition, but the issue with that is , when you edit code, if we add a new enum value and forgot to add in the string conversion function/array, it will be give lot of problems and spend time on debugging After googling, i found on solution which has only one definition, I edited it to suit my requirements. Please check the code below #include<stdio.h> #define FOREACH_WEEKDAYS(WEEKDAYS) \             WEEKDAYS(SUNDAY)   \             WEEKDAYS(MONDAY)  \             WEEKDAYS(TUESDAY)   \             WEEKDAYS(WEDNESDAY)  \             WEEKDAYS(THURSDAY)  \             WEEKDAYS(FRIDAY)  \             WEEKDAYS(SATURDAY) #define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_STRING(STRING) #STRING, enum WEEKDAYS_ENUM {         FOREACH_WEEKDAYS(GENERATE_ENUM) }; static const
Recent posts

History of C programming language

C (pronounced like the letter C) is a general-purpose computer programming language developed C (pronounced like the letter C) is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. C was designed for implementing system software, but it became so popular that its widely used for developing portable application software. C came from Thompson's B language. The main intention of C language was to make more readable programming language than the assembly language, which was used for system programming, low level access to CPU/Sytem registers and all. C was the language which evolved to be the most popular langage of all time. It can be used for making system level, low level programming, high level programming, application programming, creating compilers etc The initial development of C occurred at AT&T Bell Labs between 1969 and 1973 according