In K & R ANSI C, the only places where the question mark may be valid are:
- String literals ""
- Character constants ''
- Comments
Now you may notice that there are no macros or trigram sequences in this list.
I did not include triran sequences, as they are a compiler extension, not a "valid C". I do not want you to delete the check from your program, I am trying to say that you have already gone further than necessary for ANSI C.
I also did not include macros, because when you talk about a character that can occur in macros, you can understand two things:
- Macro Names / Identifiers
- Macronutrients
What? the character cannot be found in macro definitions (http://stackoverflow.com/questions/369495/what-are-the-valid-characters-for-macro-names), and I see the particles as regular C code, so the first list ( string literals, character constants, and comments *) should also cover them.
* Can macros correctly contain comments? Because if I use this:
#define somemacro 15
then // this is a comment not part of the macro. But what if I compile this C file with -D somemacro="15 // this is a comment" ?
source share