←back to thread

283 points ghuntley | 1 comments | | HN request time: 0.203s | source
Show context
pixelpoet ◴[] No.45135241[source]
> A few notes for the "um actually" haters commenting on Hacker News

Stay classy; any criticism is of course "hating", right?

The fact that your title is clickbaity and your results suspect should encourage you to get the most accurate picture, not shoot the messenger.

replies(2): >>45136013 #>>45136646 #
1. unwind ◴[] No.45136013[source]
I can bite (softly) on part of that, since there is C code in the post. :)

This:

    size_t count = 0;
    /// ... code to actually count elided ...
    printf("Found %ld 10s\n", count);
is wrong, since `count` has type `size_t` you should print it using `%zu` which is the dedicated purpose-built formatting code for `size_t` values. Also passing an unsigned value to `%d` which is for (signed) `int` is wrong, too.

The (C17 draft) standard says "If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined" so this is not intended as pointless language-lawyering, it's just that it can be important to get silly details like this right in C.