mardi 14 juillet 2020

compile time conditions in if statements

If I had an if statement with a condition that can be evaluated at compile time, would the compiler remove the whole if if the condition evaluates to false like this:

if (1 < 0) { puts("hello"); } 

or just remove the check if the if condition evaluates to true:

if (0 < 1) { puts("hello"); }

/* just becomes */ 
puts("hello"); 

Aucun commentaire:

Enregistrer un commentaire