Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"main()" should be "int main(void)" and other quibbles #12

Closed
Keith-S-Thompson opened this issue Jul 6, 2019 · 1 comment
Closed

"main()" should be "int main(void)" and other quibbles #12

Keith-S-Thompson opened this issue Jul 6, 2019 · 1 comment

Comments

@Keith-S-Thompson
Copy link

For all five examples in so_you_think_you_know_c.html, main() should be int 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 and int are not guaranteed, only that the range of int includes at least the range of short int. In the presence of padding bits, a conforming implementation could have sizeof (short int) > sizeof (int). The implementation-defined signedness of plain char is also relevant; it's possible to have sizeof (int) == 1 and CHAR_MAX > INT_MAX (if plain char is unsigned and CHAR_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, evaluating i++ + ++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.)

@akalenuk
Copy link
Owner

akalenuk commented Jul 6, 2019

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 :-)

@akalenuk akalenuk closed this as completed Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants