Error in my C programming

Dag-Erling Smørgrav des at des.no
Tue Feb 22 06:22:06 PST 2005


Giorgos Keramidas <keramida at ceid.upatras.gr> writes:
> The quotations seem a bit messed up, so I don't know if Peter Jeremy or
> Kathy Quinlan wrote the above paragraph.  Whoever the author was though,
> it may be worth to note that C99 *does* allow single-line comments
> delimited by //.

which leads to the following code being well-formed and well-defined
in both C89 and C99 but having different semantics...

#include <stdio.h>

int
main(void)
{
        int a, b, c;

        a = 10;
        b = 2;
        c = a //* oops! */
            -b;
        switch (c) {
	case 8:
                printf("C99 or C++\n");
		break;
	case -5:
                printf("C89\n");
		break;
	default:
		printf("can't happen\n");
		break;
	}
        return 0;
}

This is actually documented in the C99 rationale.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list