93 ms·
Sure, but would you really care whether someone knew off the top of their head that %zu is the escape sequence for size_t? Some of the stuff she shows off is pr
by sirclueless 15y ago
Sure, but would you really care whether someone knew off the top of their head that %zu is the escape sequence for size_t? Some of the stuff she shows off is pretty arcane, though pieces of it are actually useful.
Understanding the memory model and execution model is a big plus, because it lets you write correct and efficient code (and if you are using C you care about correctness and efficiency). Recalling arcana about the C99 standard is just overkill and asking someone to pull stuff like that out of a hat in an interview is asking too much IMO.
- pwaring 15y agoIf you're being sensible and using -Wall with gcc, it will pick up the %zu thing anyway: sizeof-test.c: In function ‘main’: sizeof-test.c:5:3: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘long unsigned int’ Compilers have warnings so that you don't have to remember archaic bits of C. :)
- numeromancer 15y agoYes, I would care. Someone who didn't know might notice the sizeof() and note that it returns size_t, but not know what to do about it, and end up saying "screw it" and just using "%d", which is not portable, and the program might crash when compiled for a different system. It might even run on his sytem today, but not tomorow, or run in the debug image but fail in production. I've seen this and similar things happen many-a-time.
- unwind 15y agoPet peeve alert: sizeof is not a function. It's a unary operator. The parenthesis you usually see after it are part of the argument, which for type names looks like a cast to the type in question. Like any other cast, the syntax is the type name in parenthesis. Apologies if you already knew this.
- yxhuvud 15y agoLearning arcane trivia is a side effect of learning the necessary stuff.
- dodedo 15y agoI have to work with folks who confuse size_t with int, and as a result they have overflow bugs depending on whether O_LARGEFILE is in use. So yes, I care. Not because printf format strings are terribly important, but because understanding and adhering to the type system is essential to write bug-free software.
- 0x12 15y agoIf they get overflow errors then your build process does not have the right warnings enabled/logged. Suggestion: enable -Wall and treat warnings as errors.
- pwaring 15y agoHandily, gcc has -Werror, which turns all warnings into errors. So -Wall -Wextra -Werror should catch most things.
- dodedo 15y agoOf course. You and I know they're doing it wrong, however sirclueless suggested above that type correctness is "arcane" and asks if "we would really care" when it comes to type issues in printf format strings.
- aninteger 15y agoExcept if you're using gcc (mingw) on Windows: gcc -v shows that it's been configured with --disable-werror