- Compile error - 2 Updates
James Kuyper <jameskuyper@alumni.caltech.edu>: Feb 11 02:33PM -0500 On 2/11/19 12:51, red floyd wrote: > standard, see 3.6.1/5: > "... If control reaches the end of main without encountering a return > statement, the effect is that of executing return 0;" Yes, but "the effect of executing return 0;" depends upon how the function is declared. If it's declared as returning a type that "int" can be implicitly converted to, the behavior is to convert 0 to that type and return it. If it's declared as returning any other type, or as returning void, it's a violation of a diagnosable rule specified by the standard (9.6.3p2); a diagnostic is required (4.1p2). And if the function isn't properly declared at all, that lack of declaration makes it a syntax error (11.3.5p1 - T is not optional, and is missing from this declaration) regardless of whether there's any return statement. In the particular case of main(), there's additional requirements. 6.6.1p2 specifies two different ways to declare main() that all implementations are required to accept; implementations of C++ have no obligation to accept any declarations for main() that don't match one of those two forms. This declaration doesn't match either of them. |
"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Feb 11 08:14PM +0100 On 11.02.2019 18:51, red floyd wrote: > statement, the effect is that of executing return 0;" > So it is defined, it is valid, and no warning is required. At least > as of C++03. The problem isn't lack of a `return` statement, it's the implicit `int`. Cheers!, - Alf |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment