I occasionally write code something like this:
// file1.cpp #define DO_THIS 1 #if DO_THIS // stuff #endif
During the code development I may switch the definition of DO_THIS
between 0 and 1.
Recently I had to rearrange my source code and copy some code from one file to another. But I found that I had made a mistake and the two parts had become separated like so:
// file1.cpp #define DO_THIS 1
and
// file2.cpp #if DO_THIS // stuff #endif
Obviously I fixed the error, but then thought to myself, why didn't the compiler warn me? I have the warning level set to 4. Why isn't #if X
suspicious when X is not defined?
One more question: is there any systematic way I could find out if I've made the same mistake elsewhere? The project is huge.
EDIT: I can understand having no warning with #ifdef that makes perfect sense. But surely #if is different.
A spokesman for the disaster agency said the warning was canceled after the waves made land. Unconfirmed reports also claimed that sirens did not sound in some areas because they were left without power due to the initial earthquake and did not have a secondary source of energy.
Natural WarningsGROUND SHAKING, a LOUD OCEAN ROAR, or the WATER RECEDING UNUSUALLY FAR exposing the sea floor are all nature's warnings that a tsunami may be coming.
WARNING SYSTEMThose killed in 2004 received no formal warning of the approaching waves and had almost no chance to get out of the way. Since then, millions of dollars have gone into a vast network of seismic and tsunami information centers, setting up sea and coastal instruments and erecting warning towers.
Tsunami Warning – A tsunami warning is issued when a tsunami with the potential to generate widespread inundation is imminent, expected, or occurring. Warnings alert the public that dangerous coastal flooding accompanied by powerful currents is possible and may continue for several hours after initial arrival.
gcc can generate a warning for this, but its probably not required by the standard:
-Wundef
Warn if an undefined identifier is evaluated in an `#if' directive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With