Talk:C (programming language)/Archive 14
Appearance
![]() | This is an archive of past discussions about C (programming language). Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 10 | ← | Archive 12 | Archive 13 | Archive 14 | Archive 15 | Archive 16 | Archive 17 |
Hello world, revisited
The standards-compliant "hello, world" example is only compliant for C99 and higher. I think it needs to be clarified that it isn't compliant with C89. — Preceding unsigned comment added by Tommyinla (talk • contribs) 06:53, 17 February 2013 (UTC)
- What's not C89 compliant about it? The only thing I can see is that implicit "return 0" at the end of main() is more clearly and explicitly defined in C99, although it *is* defined in C89 (2.1.2.2 Hosted environment (...) "Program termination" (...) A return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument. If the main function executes a return that specifies no value, the termination status returned to the host environment is undefined. and 3.6.6.4 The return statement (...) Reaching the } that terminates a function is equivalent to executing a return statement without an expression.). Rwessel (talk) 12:01, 17 February 2013 (UTC)
- According to the two clauses that you specified, there *is* an implicit return from main. However, the return value is undefined. Correct me if I'm wrong, but undefined behavior != standards compliant. Tommyinla (talk) 19:05, 17 February 2013 (UTC)
- You're quite correct, the value returned from main without an explicit value specifying return is undefined in C89, I was thinking of a slightly different case. But exiting main at the closing brace clearly *is* defined (which should have been my point). In any event, invoking undefined behavior only makes the program not “strictly conforming” (1.7 COMPLIANCE - A strictly conforming program shall use only those features of the language and library specified in this Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.). But I don't think this is actually undefined behavior in the usual C sense, rather just the value returned to the host environment (and clearly the program is still defined to successfully return to the host environment, but with some undefined exist status). Any issues the host environment had with that would clearly not be an issue for the C program, which has successfully finished executing. Rwessel (talk) 23:22, 17 February 2013 (UTC)
- Interesting point you make. I suppose we can say it's conforming. I did reword the last paragraph of that section though. It specifically stated that 0 was the implicit return value. I modified the verbiage to include, "According to C99 and newer." Tommyinla (talk) 12:16, 18 February 2013 (UTC)