1. 8
  1.  

  2. 5

    If sizeof really is a major cause on confusion as the author posits, then I don’t know why he had to go out of the way to come up with an even more confusing definition (and explanation) than what the spec says:

    The sizeof operator yields the size (in bytes) of its operand

    What should be spelled out explicitly is that some of the implicit conversions are not applied to operands of sizeof. But I get the feeling that many tutorials and other learning material try to keep the newbie in the dark with regard to these conversions, so they are never mentioned.

    The confusion between pointers and arrays is one that does indeed warrant some explanation, but it is by no means a concern specific to the sizeof operator.

    Also, what’s this blurb?

    Another thing to notice is that the sizeof operator does not require parentheses. This is because it is a operator not a function.

    But it requires parentheses if you want to use it on a type name! Operator vs function does not matter. What the matters is what the syntax rules look like. The cast operator requires parentheses too.

    1. 2

      But how big is a char? According to the C Specification ISO/IEC 9899:TC3 Chapter 5.2.4.2.1 (the first one I could find on google) it is 1 byte (8 bits).

      Nope. If you read the section referenced a little more carefully, you’ll note that the standard says that 8 is the minimum value for CHAR_BIT, not the exact value. While it’s not terribly common anymore, architectures having non-8-bit-bytes used to be somewhat typical. “Byte” ≡ smallest addressable unit of storage on a machine. “Octet” ≡ 8 bits.

      When given a VLA, sizeof waits until runtime to compute the sizeof the variable. This is the only time that sizeof will operate at runtime instead of compile time.

      Incidentally, this means that the argument to sizeof will be evaluated at runtime.

      The things I find most confusing about sizeof tend to be things that are actually confusing to me about Cxx. Namely, the behavior in sizeof changes between C and Cxx in ways that can often be unexpected for C developers.