New answers tagged

2

static const is more secure, but not for the reasons you're thinking of. It permits the compiler to perform type checking, which will catch a class of bugs that #define won't permit it to catch. In regards to your specific concerns: "#define" is embedded in compiled code, while static int leaves a variable in memory, which a user can change the value ...


0

From my understanding #define will indeed replace TimeLimit with the literal 30 when the preprocessor runs. It is not clear to me what the standard states on static const variables (if anything). For instance, if the compiler supports constant folding and the variable is only used in constant expressions, the expressions are evaluated at compile time and it ...



Top 50 recent answers are included