Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: what is the output |
| Date | 2011-07-05 08:34 -0700 |
| Organization | None to speak of |
| Message-ID | <lnmxgs3fmo.fsf@nuthaus.mib.org> (permalink) |
| References | <fde0c807-8924-4328-887b-42495fcc80c5@d26g2000prn.googlegroups.com> <iutat4$tg4$1@dont-email.me> <op.vx4jegrf5qv6o3@toshiba-laptop> <iutvth$h6e$1@dont-email.me> |
Eric Sosman <esosman@ieee-dot-org.invalid> writes:
> On 7/4/2011 10:19 PM, Morris Keesan wrote:
>> On Mon, 04 Jul 2011 17:21:38 -0400, Martin Ambuhl
>> <mambuhl@earthlink.net> wrote:
>>> On 7/3/2011 12:32 PM, vinay kumar wrote:
>>>> main()
>>>> {
>>>> int d=010;
>>>> printf("%d",d);
>>>> }
>>>>
>>>> please give with explanation
>>>
>>> Several diagnostics, since
>>> a) main incorrectly has no return type (should be int)
>>> b) printf has no prototype (#include <stdio.h>)
>>> c) for pre-C99 compilers, main fails to return a value.
>>
>> But since main is not declared with a return type, this lack of a return
>> shouldn't trigger a diagnostic, should it?
>
> C99: Yes, because defining a function without specifying a
> return type requires a diagnostic. (The "lack of a return" need
> not produce a diagnostic, and is in fact well-defined for hosted
> environments because of a vile pandering to sloppy programmers.
> But the "not declared with a return type" is verboten.)
In fact it's a syntax error. "main() { ... }" doesn't satisfy
the syntax for a function definition, and a compiler needn't even
recognize it as one. (Probably most C99 compilers use grammars
that recognize C90-style declarations, for the purpose of producing
meaningful error messages.)
> C90: Implementation's discretion. No diagnostic is required,
> but all diagnostics are (as always) permitted. ("Warning: Code was
> written on a Thursday. I never could get the hang of Thursdays.")
Right. In C90, a missing return type is equivalent to an explicit
return type of "int". The declaration is perfectly correct C90
(ignoring an obscure quibble about "main()" vs. "main(void)").
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
what is the output vinay kumar <vinay5b9@gmail.com> - 2011-07-03 09:32 -0700
Re: what is the output "Joachim Schmitz" <nospam.jojo@schmitz-digital.de> - 2011-07-03 19:43 +0200
Re: what is the output Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-03 13:47 -0400
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-03 12:15 -0700
Re: what is the output Chad <cdalten@gmail.com> - 2011-07-03 13:55 -0700
Re: what is the output "osmium" <r124c4u102@comcast.net> - 2011-07-03 16:20 -0500
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-03 14:24 -0700
Re: what is the output Chad <cdalten@gmail.com> - 2011-07-03 16:13 -0700
Re: what is the output "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-07-03 21:10 -0400
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-04 14:22 -0700
Re: what is the output Todd Carnes <toddcarnes@gmail.com> - 2011-07-05 03:30 +0000
Re: what is the output John Gordon <gordon@panix.com> - 2011-07-05 02:26 +0000
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-03 18:30 -0700
Re: what is the output Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-03 21:58 -0400
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-04 17:10 -0700
Re: what is the output Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-04 21:42 -0400
Re: what is the output Shao Miller <sha0.miller@gmail.com> - 2011-07-04 22:51 -0400
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-06 16:23 -0700
Re: what is the output Michael Press <rubrum@pacbell.net> - 2011-07-03 21:23 -0700
Re: what is the output Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-07-03 14:06 -0600
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-03 18:19 -0700
Re: what is the output Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-03 22:12 -0400
Re: what is the output Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-07-03 21:16 -0600
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-04 13:59 -0700
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-04 17:15 -0700
Re: what is the output Martin Ambuhl <mambuhl@earthlink.net> - 2011-07-04 17:21 -0400
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-04 17:27 -0700
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-04 18:07 -0700
Re: what is the output Tim Rentsch <txr@alumni.caltech.edu> - 2011-07-06 17:08 -0700
Re: what is the output "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-07-04 22:19 -0400
Re: what is the output Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-07-04 23:19 -0400
Re: what is the output Keith Thompson <kst-u@mib.org> - 2011-07-05 08:34 -0700
Re: what is the output Shao Miller <sha0.miller@gmail.com> - 2011-07-04 18:26 -0400
Re: what is the output Todd Carnes <toddcarnes@gmail.com> - 2011-07-05 03:36 +0000
csiph-web