Reputation: 2594
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?
Upvotes: 15
Views: 548
Reputation: 239341
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;
}
Upvotes: 6
Reputation: 9972
Two examples:
C99 has -3/2
as Defined Behaviour (namely, to truncate to zero).
C99 has -1<<1
as Undefined Behaviour (but not C89).
Also, in the past I've run into problems with 64-bit enums, such as enum {mask = 1ULL << 32}
, but I don't recall if the compiler was silent, or just quietly did the wrong thing.
Upvotes: 3
Reputation: 8075
Integer division can produce a different result, depending on which c89 implementation you used.
Does either ANSI C or ISO C specify what -5 % 10 should be?
Upvotes: 2