33

I am working with a legacy code and found this:

#if (1 > 1)
//define some function
#endif

Not sure, how this can be any different from the more typical #if 0, to comment out the code? Any thoughts?

dreamcrash
  • 47,137
  • 25
  • 94
  • 117
MIbrah
  • 1,007
  • 1
  • 9
  • 17
  • 18
    Probably, initiallly there were some other things than `1`s.. And then they gradually mutated. No, there is no difference. – Eugene Sh. May 05 '16 at 21:05
  • 10
    Here's a wild guess. I often use `#if 0` to disable sections of code during development/debugging. Before releasing said code, I grep for `#if 0` to make sure that everything's back to normal. So I would use something other than `#if 0` for a block of code that needs to be disabled through multiple release cycles. However, I my case it's `#ifdef something_that_cant_possibly_be_defined`. – user3386109 May 05 '16 at 21:19
  • 18
    Change it to `#if (!!(1 > 1) != 1)` - mysteries are fun. – void_ptr May 05 '16 at 21:21
  • 8
    Well, inspired by @user3386109 I can come up with another crazy idea: You can number the disabled blocks (for identification) by `#if (1<1)`, `#if (2<2)` and so on... – Eugene Sh. May 05 '16 at 21:21
  • Thanks all, the reason I asked this question cuz I believe there is a purpose to everything even if it is hidden. Not sure though if this applies to programming :) – MIbrah May 05 '16 at 21:25
  • @MIbrah If you replace the "*purpose*" by "*reason*" I could even agree with you. But it is not necessarily a good reason... – Eugene Sh. May 05 '16 at 21:26
  • 2
    There are lots of strange superstitions about the preprocessor, this looks like one of the more bizarre ones. It certainly has no well-defined special meaning (that is, other than it's truly equivalent to `#if 0`), so your guess is as good as ours... – Steve Summit May 05 '16 at 21:31
  • Once I have seen a snippet of a C code hiding a [brainf@ck](https://en.wikipedia.org/wiki/Brainfuck) program in it. `#if (1 > 1)` is hiding one BF instruction in it... – Eugene Sh. May 05 '16 at 21:40
  • 1
    Some IDEs use syntax highlighting for `#if 0` specifically – M.M May 06 '16 at 00:08
  • Could it also be the result of some automatic code generation, where the original produced code was something like `#if SOME_TAG > 1` that then degenerated to `#if 1> 1`? – Roberto Caboni Jan 30 '21 at 13:12

2 Answers2

70

Both expressions are false, so the code is never compiled.

Here are potential explanations for why the programmer did not want to use the obvious #if 0 preprocessor directive to disable a section of code:

  • the programmer did not want grep '#if 0' to find his code snippet.
  • the local coding conventions disallow #if 0 and possibly enforce this rule with a script. The programmer found a contorted workaround.
  • some programmer's editors (eg vim) colorize #if 0 sections as comments, using a different preprocessor expression defeats this.
  • the programmer might have thought a boolean expression was required after #if. The use of parentheses supports this explanation, but only the programmer can tell.
  • the original code had #if (OPTION > 1) and OPTION was changed to 1 with a sed script or some other global text replacement method.
  • the programmer may have wanted to attract the next reader's attention. Either for a humorous purpose or some other obscure goal. Goal achieved in this case.
  • as noted in some of the comments, this could be a lame attempt at obfuscating the code, to increase job security... For this purpose, I suggest the gets operator: #if (0 <- 1) or the crawling adder: #if (1 <~~ 1).
chqrlie
  • 131,814
  • 10
  • 121
  • 189
  • 1
    @user4581301: I'm not sure how this would buy *employment insurance*, but I shall add *reader warning*. – chqrlie May 05 '16 at 22:31
2

I think the the (1 > 1) acts as a comment for the reader. It is a smiley or some other emoticon! :-)

It would also have been possible to write (0>0) or similar.

jotik
  • 17,044
  • 13
  • 58
  • 123
  • `0v0` == owl, `=^.^=` == cat – cat May 06 '16 at 13:37
  • @cat I doubt the `=^.^= == cat` version will ever work, but you can get similar behaviour if you modify the owl example to `#if (OvO != owl)` – jotik May 06 '16 at 15:15
  • You just need a struct named `=^` with a member `^=`... oh, this is C. :P (I don't think `0v0` is valid C syntax either.) – cat May 06 '16 at 15:19
  • @cat That's why I used `O`-s instead of zeroes. `Ov0` would also work thou. – jotik May 06 '16 at 16:17
  • 1
    But the `0`s get little dots inside them in this monospace font c: – cat May 06 '16 at 17:03