0
When to use #define or const in C?
The #define directive uses no memory and is used by the preprocessor to manipulate the source code before compilation. The const function is used to prevent the source code from changing the value of a certain identifier, but in doing so it requires memory. Under what circumstances do programmers use these?
3 Respostas
+ 4
One simple idea I use is to use *const* everywhere and use #define only where I can't use *const*, like while defining header guards.
As in C ( unlike C++ ), *const* qualified types are not "true" constant expressions, so you will find a lot more cases where you might want to define a macro over *const*
+ 3
https://www.includehelp.com/cpp-tutorial/difference-between-const-and-define.aspx
https://stackoverflow.com/questions/1674032/static-const-vs-define-vs-enum