Funny if only marginally related fact: even though neither the C++11 syntax

  if (int x = foo(); x) { ... }
nor the C++98 syntax

  if (int x = foo()) { ... }
is supported in C99, it still introduces the rule that the entire if statement is a scope (which it wasn’t in C89). So as a party trick, here’s a way to check for C99 without using the preprocessor:

  int c99() {
      enum { C99 = 1 };
      {
          if (sizeof(enum { C99 = 0 })) { }
          return C99;
      }
  }
I make no promises about the behaviour of this code on insufficiently anal compilers like TCC.

This is very cool, although a more compact way to check for single line comments (introduced in C99) versus division using "//* */". I used that trick here:

https://github.com/ioccc-src/winner/blob/a1c86c8a7a533e3c2cd...

You gave an IOCCC snippet as an example of a C99 coding trick you know? I mean, the code looks visually cool, but it's funny to explain a code concept using code shaped like an anime character. (At least that's what I think it is.)

I don't know how to link to just a specific part of the line, but the interesting bit is at the end of line 16 and the start of line 17:

    x*=02//* */2
          -1;
With C89, this is evaluated as "x *= 02 / 2 - 1", or "x *= 0".

With C99, this is evaluated as "x *= 02 / -1", or "x *= -2".

> I make no promises about the behaviour of this code on insufficiently anal compilers like TCC.

But tcc isn't a C++ compiler at all?

[deleted]

tcc version 0.9.28rc returns "1", whatever that means.

Pretty sure that means that tcc at least believes it is a C99 (or later) compiler; if it conformed to an earlier spec it (probably?) would have considered the inner `enum { C99 = 0 }` definition to be still in scope, and the return value would be 0.

I think.

That’s correct. I did check before posting that TCC 0.9.27 on Godbolt returned zero here, but I didn’t look beyond that. Evidently things have changed since that release.