Discussion:
odd behavior
Michael Williamson
2014-08-28 21:20:13 UTC
Permalink
Hi,

Using gcc version 4.6.3 including the parameter -Wall, I discovered
that it gives a warning message for missing closing double quotes
inside sections of code that are not even used due to #if ... #endif
statements. That seems odd.

Just FYI,
-Mike
Jędrzej Dudkiewicz
2014-08-29 05:37:18 UTC
Permalink
I've seen it few times, but was always my fault and section was in
fact compiled. Try preprocessing your input file using -E option and
check if it really isn't used.

On Thu, Aug 28, 2014 at 11:20 PM, Michael Williamson
Post by Michael Williamson
Hi,
Using gcc version 4.6.3 including the parameter -Wall, I discovered
that it gives a warning message for missing closing double quotes
inside sections of code that are not even used due to #if ... #endif
statements. That seems odd.
Just FYI,
-Mike
--
Jędrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.
Jonathan Wakely
2014-08-29 09:11:59 UTC
Permalink
Post by Jędrzej Dudkiewicz
I've seen it few times, but was always my fault and section was in
fact compiled. Try preprocessing your input file using -E option and
check if it really isn't used.
No, it definitely happens in code that isn't compiled, try it:

#if 0
const char* s = ";
#endif
int main() { }

x.c:2:17: warning: missing terminating " character [enabled by default]
const char* s = ";
^
Jędrzej Dudkiewicz
2014-08-29 10:36:03 UTC
Permalink
Ah-ha! You're right. Now I see that this warning is issued by
preprocessor, not by compiler. Now that I think about it, it seems
logical. Preprocessor has to tokenize input to perform substitutions
and such, so even if code isn't meant for compiler, it must follow
some rules - ifdefined parts of code are not comments. Is that right?
Post by Jonathan Wakely
Post by Jędrzej Dudkiewicz
I've seen it few times, but was always my fault and section was in
fact compiled. Try preprocessing your input file using -E option and
check if it really isn't used.
#if 0
const char* s = ";
#endif
int main() { }
x.c:2:17: warning: missing terminating " character [enabled by default]
const char* s = ";
^
--
Jędrzej Dudkiewicz

I really hate this damn machine, I wish that they would sell it.
It never does just what I want, but only what I tell it.
Segher Boessenkool
2014-08-29 12:12:01 UTC
Permalink
[Please don't top-post. Thanks.]
Post by Jędrzej Dudkiewicz
Post by Jonathan Wakely
#if 0
const char* s = ";
#endif
int main() { }
Ah-ha! You're right. Now I see that this warning is issued by
preprocessor, not by compiler. Now that I think about it, it seems
logical. Preprocessor has to tokenize input to perform substitutions
and such, so even if code isn't meant for compiler, it must follow
some rules - ifdefined parts of code are not comments. Is that right?
C11 6.4/3 says the lonely quote is undefined behaviour. Your program
might or might not work (the same) with a different (version of the)
compiler. So a warning is good.


Segher

Continue reading on narkive:
Loading...