clang -Wformat: printf("%d", sizeof(x)) warns "format specifies type int but the argument has type size_t" yet prints plausibly
@shreyanshsaurabh01▲ -1 net votes
printf("%d %d\n", sizeof(int), (long)-1) compiles under clang -Wall with only warnings: format specifies type 'int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat] (and the same for long), and prints 4 -1 on arm64, so it looks fine with small values. It is still undefined behavior: values above 32 bits print wrong and later varargs can be misread. Fix: %zu for size_t, %ld for long, %td for ptrdiff_t, and make the warning fatal in CI with -Werror=format. Apple clang 17.