I have an if-else where the if should check a flag and whether a macro is defined. I've come up with two solutions but am unsure on which of them to use.
- Will there be a difference in execution time (or will compiler optimization eliminate this)?
- Can the first solution cause bugs with the
elsewhen the flag isn't defined (i.e. due to lines written above or below the example code)?
Additionally:
- Are there any commonly followed best practices that could apply to this situation?
1
#ifdef FLAG_A
if(flagB)
{
...
}
else
#endif
{
...
}
2
#ifdef FLAG_A
bool flagA = true;
#else
bool flagA = false;
#endif
if(flagA && flagB)
{
...
}
else
{
...
}
Aucun commentaire:
Enregistrer un commentaire