Comment

Comment by kazinator

Something is overlooked. Note that:

    int *a[] = { 1, 2, 3 }
violates a constraint in the C language; an ISO C conforming implementation must issue a diagnostic --- and, additionally, it may stop translating and reject the program.

Why? Because expressions of type int are being used to initialize elements of type pointer to int, without a cast.

The first step is operating your compiler such that you get the required diagnostics out of it, or at least the important ones, and then some. For instance, with gcc:

    # C90
    gcc -Wall -ansi ... # some would add -pedantic

    # C99
    gcc -Wall -std=c99 ...
and then, don't ignore diagnostics that are "mere" warnings!

And, of course, passing a pointer argument to a "%d" conversion specifier in printf is undefined behavior.

parent kazinator 12 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton