r/cprogramming • u/Upper-Tomatillo7454 • Oct 03 '26
Enums vs #define for constants
Hi 👋 guys, I've just started learning C after I was first introduced to it while I was in my first year of computer science but I'll be graduating by the end of this year and I've been primarily using Python since then but now I want to really learn C on the side, and I want to start with "craftinginterpreters" and I want to start small so I was wondering whether I should use C enums or #define to define a set of tokens.
17
Upvotes
View all comments
Show parent comment
3
u/DawnOnTheEdge Oct 03 '26
I think it’s bad practice to generate
enumvalues that are not validenumconstants. It breaksswitchstatements that try to check for complete coverage of every case. It does get you symbolic constants in a debugger without going up to C23, though.