spinozagl
spinozagl

Reputation: 125

gcc -W -Wall -O -pedantic -std=c99 vs clang with same options

Trying to output a pointer's address in decimal form using the %zu conversion specifier. Runs okay as expected except that GCC warns

format ‘%zu’ expects type ‘size_t’, but argument 4 has type ‘long int *’

GCC options used are shown in the question. GCC still warns without any options set (other than -std=c99). clang however, does not issue any warnings at all with the same options. This is on OS X 10.7. Just curious why clang isn't issuing any warnings? Is GCC "better" than clang for debugging/compiling?

Upvotes: 0

Views: 1392

Answers (2)

Stephen Canon
Stephen Canon

Reputation: 106317

This appears to be specific to the z size modifier in clang; you do get a warning with %lu, %u, %hu, etc. (Even without any options)

Generally speaking, it has been my experience that clang has more useful warning messages than GCC does. This is an exception to that experience. I'll file a bug.

Upvotes: 2

ams
ams

Reputation: 25599

You need to put in a cast, but beware that if your code ever runs on a machine where size_t is not the same size as a pointer then it'll do the wrong thing. Probably fine though ...

printf ("%zu\n", (size_t)my_ptr);

Upvotes: 0

Related Questions