
C, what the fuck??! - bowero
https://bowero.nl/blog/2019/12/15/c-what-the-fuck/
======
zeotroph
This is about that ancient EBCDIC (IBM's ASCII "competitor") specific hack
called trigraphs, which in modern compilers are opt-in anyhow: "To understand
this, I have to admit one thing: I have to pass -trigraphs to a modern version
of gcc before this actually works. "

C++17 actually removed support for these.

~~~
fanf2
Trigraphs were not specific to EBCDIC: they were also a bad accommodation for
the ISO 646 ASCII variants that supported European languages, which used
characters {\|} etc. for letters. This is why the newer better header with
alternate spellings for restricted character sets is called <iso646.h>

[https://en.wikipedia.org/wiki/ISO/IEC_646](https://en.wikipedia.org/wiki/ISO/IEC_646)

~~~
burfog
The reasonable accommodation is to substitute with characters that are
available in the ISO 646 ASCII variant being used, preferably the characters
with the same binary representation as in US ASCII.

Outside of silly games like IOCCC, did anybody actually use trigraphs? I find
it really hard to believe that anybody tolerated trigraphs for serious C
programming. Was there an obscure European government agency that actually
wrote code with trigraphs?

~~~
boomlinde
IBM opposed their removal in C++1x

From [http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2009/n291...](http://www.open-
std.org/jtc1/sc22/wg21/docs/papers/2009/n2910.pdf)

 _> The biggest argument against deprecating trigraph is the fact that we know
there are source code from world-wide companies, based on an internal survey
of our customer problem reports that make heavy use of trigraphs for one
reason or another, and customer testimonials. Google code search doesn't find
them because these are proprietary code. Further discussions with some of
these customers have shown serious dissatisfaction with WG21’s intention to
deprecate trigraphs, because they do not wish to make any changes to their
source code. It doesn't seem fair to force this group of existing users to
change their source code for no apparent benefit, other then reducing an
annoyance to another group._

ISO 646 is probably nowhere near as relevant to their argument as EBCDIC is.

 _> Trigraph deprecation is vexing for existing world-wide companies (of which
IBM is one such user) because of their use of EBCDIC variant code pages. It
makes it difficult to start in a code page neutral manner, establish what the
active code page is, then start using invariant characters. We use a pragma
filetag("IBM-1047") to toggle the code page, then we can use #. Prior to that
we are in a code page neutral environment and must use the trigraph ??=_

------
segfaultbuserr
Digraphs were supposed to be a easier-to-read alternative to trigraphs.
Unfortunately, the extended list of digraphs with many additional logic
operators by C++ never entered C, i.e.

    
    
        %:%:    ##
        compl   ~
        not     !
        bitand  &
        bitor   |
        and     &&
        or      ||
        xor     ^
        and_eq  &=
        or_eq   |=
        xor_eq  ^=
        not_eq  !=
    

C only has basic ones (still more intuitive than trigraphs).

    
    
        <:  [
        :>  ]
        <%  {
        %>  }
        %:  #
    

Last time, I had to type a C program on a touchscreen, and those symbols were
extremely difficult to enter. I knew digraphs can help, but then realized that
I couldn't use the digraphs for logic operators without programming C under
C++.

~~~
hvdijk
C has the named operators as macros in <iso646.h>.

~~~
segfaultbuserr
Great tip, thanks. Have to remember this magic ISO standard number.

~~~
ncmncm
Also, have to remember to #undef them in any file that includes something that
includes iso646.h.

------
pwdisswordfish2
TL;DR: Trigraphs. That at least makes the ‘??!’ in the title meaningful.

It's still clickbait, though.

~~~
krzat
Especially that it requires enabling a compiler flag. If you need to require
that then you could require "#define true false" as well.

------
threatripper
What is the probability of something like this appearing in a normal program
written by somebody who is unaware of trigraphs?

I am also not aware of any professional who would use multiple question marks
in any kind of serious code that could be read by anybody else because that
kind would reflect negatively on the perception of his professionalism.

~~~
hvdijk
Nice "No true Scotsman" logic there. Sure, if you see multiple question marks
as an indicator of unprofessionalism, then by definition, no professional
would use that. At the same time, your definition of professional is not one
that is useful in any other context.

In code written by people whose job it is, in part, to write code, i.e. what I
would call professionals, multiple question marks do sometimes occur.

~~~
threatripper
Did I really produce a Scotsman there? I would break it down like this:

* Professionals want to appear professional to the people who pay them.

* People who read the code can have an influence on the people who select which professional gets hired. (At least negatively if they find examples of poor practices.)

* Professionals therefore avoid any behavior that would be interpreted as unprofessional.

* Multiple question marks appear unprofessional and are therefore avoided. (Or would you concur???)

* I could not find a counterexample in my memory.

If this can be interpreted in a "no true Scotsman" way then it would be: "All
Scotsmen who showed the behavior have been denied the citizenship." and then
in turn they really wouldn't be true Scotsmen anymore because they lost the
citizenship.

~~~
hvdijk
I think that last point illustrates the problem: you base your idea of
"professional" on the professionals you have worked with or whose code you
have read, who might not write such things. At the same time, in code I have
read, I have seen it in ways that did not look out of place to me. What that
tells me is that this is not a professional vs. unprofessional thing, it is
just different programming norms. It is similar to how I think we can agree
that neither tabs nor spaces are unprofessional, but insisting on either in a
codebase already written using the other style is.

------
kosma
The author purposely misleads the reader by doing syntax highlighting wrong. A
trigraph-aware editor would keep the third line green.

~~~
spacemanmatt
Plot twist: Many developers are using editors that are not trigraph-aware.

------
mekazu
> Therefore, this line actually says:
    
    
        !didIMakeAMistake() || CIsWrongHere();
    

> If you understand how short-circuit evaluation works, you can understand
> that this will result in the following:
    
    
       if (!didIMakeAMistake()) 
          CIsWrongHere();
    

Can someone explain this? I’d have thought that was right without the !

~~~
segfaultbuserr
It must be a typo.

Function calls have the highest priority here, followed by logic NOT and logic
OR.

    
    
        !didIMakeAMistake() || CIsWrongHere();
    

_!didIMakeAMistake()_ is evaluated first ( _or you can say didIMakeAMistake()
is executed and evaluated first, then its result is inverted and checked_ ),
if it's true, evaluation is finished. If it's false, _CIsWrongHere();_ is
evaluated.

It is indeed equivalent to

    
    
       if (didIMakeAMistake())  /* !didIMakeAMistake() == false? */
          CIsWrongHere();
    

Without the invertion.

~~~
bowero
Thank you guys so much! I've changed it immediately.

------
purplezooey
Well, I did always think less of people who // wrote comments like this????

------
Yuioup
Seriously, at this point C should be considered dangerous and should be
actively discouraged. I would even go so far as to legislate it. We can't have
this sort of thing in 2019.

~~~
0xdead
Please don't comment on the state of programming in 2019 if you're an Angular
developer.

~~~
Yuioup
Angular is one of the many tools I use.

