Closed Keith-S-Thompson closed 5 years ago
Yes, you're absolutely right. Thank you!
I've updated the page just now.
Sorry for being sloppy with the snippets. This was among the first pages for Words and Buttons, I just made a remake of an old Medium post to see what it's like to write everything by hand. I never expected it to get so much attention :-)
For all five examples in
so_you_think_you_know_c.html
,main()
should beint main(void)
.In C90 (which is 19 years old and has been replaced by two later editions), a function definition with empty parentheses is an obsolescent feature.
In C99 and later, the "implicit
int
" rule was dropped, and omitting an explicit return type from a function definition is invalid (I think it's a syntax error, or it might be a constraint violation).On to other quibbles:
In the second example, the relative sizes of
short int
andint
are not guaranteed, only that the range ofint
includes at least the range ofshort int
. In the presence of padding bits, a conforming implementation could havesizeof (short int) > sizeof (int)
. The implementation-defined signedness of plainchar
is also relevant; it's possible to havesizeof (int) == 1
andCHAR_MAX > INT_MAX
(if plainchar
is unsigned andCHAR_BIT
is at least 16).In the third example, the numeric value of
' '
is implementation-defined (and you used LEFT SINGLE QUOTATION MARK characters rather than apostrophes for the character constant).In the fifth example, the operator precedence of the
++
operator is well defined. Only the order of evaluation is unspecified. The description could imply that the possible results are limited to the possible orders of evaluation, but in fact the behavior is completely undefined; in principle, evaluatingi++ + ++i
could make demons fly out of your nose. (Of course that can't happen, but if it did it would not violate the C standard.)