6 ms·
No mention of trigraphs? They are one of my favourite obscure C language features that I've never used. Excerpt from GCC man page: Trigraph: ??( ??)
by vq 7y ago
No mention of trigraphs? They are one of my favourite obscure C language features that I've never used.
Excerpt from GCC man page:
Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??-
Replacement: [ ] { } # \ ^ | ~
Missing backslash on your keyboard? No problem, just type ??/ instead.
- MawKKe 7y agoMore than once have I written something like this if(condition) printf("WTF??! value: %d", value); ...only to have the compiler nag me about it. That's pretty much the only situation I've come across trigraphs :)
- goatinaboat 7y agoIIRC these are a legacy of BCPL
- pdw 7y agoThe story I heard was that the trigraphs were added during standardization because ISO 646, the international version of ASCII, did not require the characters [ \ ] { | }. Fun fact: ISO 646 is also the reason that IRC allows these characters in nicknames. IRC was created in Finland, and the Finnish national standard had placed the letters Ä Ö Å ä ö å at those code points. Edit: That doesn't explain the trigraphs for # ^ ~. I'm guessing some EBCDIC variants lacked those. Or some other computer vendor on the committee still supported some other legacy character set.
- jandrese 7y agoI had to use them once on a truly ancient amber screen serial terminal that lacked { and } on the keyboard. That was back in the 90s and the terminal was completely obsolete at the time but I needed to write a tiny hack program to solve an immediate problem. I remember only knowing about them in the first place from an odd compiler warning I'd seen on a different program.
- CarlRJ 7y agoThey weren't in K&R. I recall a story about a standardization meeting, on the way to ANSI C, where representatives from some European(?) country that didn't have some of the necessary punctuation on their country-specific keyboards, essentially snuck the trigraphs into the spec when the other representatives weren't looking.
- p_l 7y agoTrigraphs are also necessary on IBM Z if you don't want to (or can't) switch from most standard EBCDIC code pages to the special C code page
- johannes1234321 7y agoAfter long debates (since IBM needs them in EBCDIC machines, like z/Series) they were dropped from C++ (I believe C++17, but might already be C++14) so if you use them in a header this might cause incompatibilities.
- cpeterso 7y agoRelated to trigraphs are the alternative logical operator keywords like `and` and `or`. I'm surprised people don't use them more often because they're nicer to read than && and ||. In C, you must #include <iso646.h> but I think they're standard keywords. C++ code example on Godbolt: https://godbolt.org/z/ED6tXK https://godbolt.org/z/ED6tXK https://en.cppreference.com/w/cpp/language/operator_alternative https://en.cppreference.com/w/cpp/language/operator_alternat...
- paulrpotts 7y agoHmmm... I would not prefer using "and" and "or" because that syntactic sugar obscures whether the bitwise or logical operations are intended. You get really used to reading && and || as "and" and "or" in your head after the first two decades of C programming : )
- jandrese 7y agoI can safely say that I have never #included iso646.h in my life.