Live data from Hacker News

C, what the fuck??!

bowero.nl

11–20 of 38 posts

Re: C, what the fuck??!

#11
> 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 !

Re: C, what the fuck??!

#12

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 symbo…

C has the named operators as macros in .

Re: C, what the fuck??!

#13
post #8

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.

I would definitely vote for you.

Re: C, what the fuck??!

#14
post #8

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.

The sad thing is that in safety critical embedded systems often the only choice you have is C and C++ because nobody would shell out for ADA developers. Rust would be a contender as well, however I'm not sure how many embedded targets that aren't major (like arm) even have a target.

Re: C, what the fuck??!

#15
post #11

> 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 !

[deleted]

Re: C, what the fuck??!

#16
post #11

> 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 !

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.

Re: C, what the fuck??!

#17
post #12

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 symbo…

C has the named operators as macros in .

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

Re: C, what the fuck??!

#18
post #10

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.

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.

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.

Re: C, what the fuck??!

#19
post #11

> 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 !

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 (didIMakeAMista…

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

Re: C, what the fuck??!

#20
post #6

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.

The chance of this accidentally happening is almost 0. This is what `gcc` does: `test.c:6:31: warning: trigraph ??/ ignored, use -trigraphs to enable [-Wtrigraphs]`

So it would take some clueless developer who adds the compiler flags to get rid of the warnings during the yearly code cleanup season.

Therefore the probability of this happening by accident is 0 but the probability of this happening by incompetence (after the trigraph already slipped in undetected) hovers around 82%.

Post reply on HN