Trigraphs – yecch
There is a usenet news group called comp.lang.c. It is mostly populated by officious pedants who argue about fine details of the standard(s) and the right way to perform very minor programming tasks. It is a useful resource when you run into the murkier obscure corners of the C programming language. Once upon a time I posed the following question.
The other day I wanted to put three successive question marks in a string. Frex, “(???).%s.%s”. My trusty antique gcc compiler converted the last two ‘?’s into a ‘]’ along with a warning that it was doing a trigraph conversion.
Now, me, I know from nothing about trigraphs – never used them, hope never to use them – so I was caught by surprise. My elderly copy of K&R; described them but I didn’t see anything about getting around them.
So. How is one supposed to get three successive question marks into a string?
The AnswerHere are a couple of the answers from the savants:
"(?""?""?).%s.%sn" "(??""?).%s.%s" will do.
That doesn’t seem right to me, but what do I know. As I read that there are two strings there, to wit “(??” and “?).%s.%s”. Are you telling me that two adjacent strings will be merged into one string. If that’s so I’m certainly surprised and I’ve learned something quite unexpected. Does this mean I can write printf(“x””y”) and I will get “xy” as an output?
What I did
It ended up that I learned something. I also decided I didn’t really need to know any of this nonsense. Instead I decided that one question mark would do quite nicely. Some things just aren’t worth the trouble.
This page was last updated March 3, 2012.