Search code examples
clanguage-lawyerc99c89

What C program behaves differently in run-time when compiled with C89 and C99?


I found the following snippet (I think in Wikipedia) that creates a different run-time when C++ comments are recognized than when not:

int a = 4 //* This is a comment, but where does it end? */ 2
  ;

But until now that's been the only one (variants excluded).

I'm not interested in differentiating using __STDC__ and the like, and not in programs that C89 will not compile.

Are there other programs/snippets producing a different run-time with C89 than C99?


Solution

  • This program will print 0.000000 on a conforming C89 implementation and 1.000000 on a conforming C99 implementation:

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        double d = strtod("0x1", NULL);
        printf("%f\n", d);
        return 0;
    }