Hacker News new | past | comments | ask | show | jobs | submit login

Very good.

A pet peeve is that it consistently says "sizeof()", like this:

You can use the sizeof() operator to determine how many bytes of memory a certain type uses. (I know, sizeof() looks more like a function than an operator, but there we are.)

BUT: sizeof does not in fact need the parentheses always!

Syntactically they are part of the argument, and only needed when the argument is a type name, i.e. the argument looks like a cast to that type.

So:

    int x;
    printf("%zu == %zu\n", sizeof x, sizeof (int));
It's very annoying to see the guide kind of glance off the way things really are, into confusion.

Very glad to see it doesn't cast the return value of malloc(), too. :)




Simply referring to it as the 'sizeof operator' would be preferable. Otherwise ignoring the ability to drop the parentheses seems fine though.

That way the author presents a simple, useful conceptual model and hints that it's actually a little more complicated than they described. Seems like a good trade-off, as there's lots of stuff to learn, and sizeof's hidden weirdness is unlikely to bite any students. When writing code, there's basically no drawbacks to just following the simpler rule of always using parentheses and it makes expressions a little easier to follow [1].

[1]: https://lkml.org/lkml/2012/7/11/103


About casting the malloc() : http://c-faq.com/malloc/mallocnocast.html


Yeah, that's a good resource. I also recommend https://stackoverflow.com/questions/605845/do-i-cast-the-res....




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: