sizeof() operator in if-statement

  1. sizeof is not a function, it’s an operator. The parentheses are not part of the operator’s name.
  2. It’s failing because the value generated has the unsigned type size_t, which causes “the usual arithmetic conversions” in which -1 is converted to unsigned, in which case it’s a very large number.

Basically you’re comparing 4 > 0xffffffffu, or something close to that at least. See this question for details.

Leave a Comment