By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

question on main( )

P: n/a
Suppose the return type of main is void.

void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.

I use return type as int only. But for knowledge sake I am asking this
question.

Mar 7 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
su**************@yahoo.com, India wrote:
Suppose the return type of main is void.

void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.
Yes. A diagnostic is required.

Mar 7 '07 #2

P: n/a
"santosh" <sa*********@gmail.comwrites:
su**************@yahoo.com, India wrote:
>Suppose the return type of main is void.

void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.

Yes. A diagnostic is required.
I don't believe so. C99 allows the main function to be defined in one
of the two normal ways "or in some other implementation-defined
manner". Even if the implementation doesn't define another manner for
declaring main, the requirement is not a constraint or a syntax rule,
so no diagnostic is required; it invokes undefined behavior.

The rules are similar for C90, except that the older standard doesn't
explicitly allow implementation-defined forms.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 7 '07 #3

P: n/a
santosh wrote, On 07/03/07 03:49:
su**************@yahoo.com, India wrote:
>Suppose the return type of main is void.

void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.

Yes. A diagnostic is required.
C&V? I know the standard specifies exactly two variants for main (and
allows the implementation to define more) but I don't believe that it is
in a constraint, so I think it is undefined behaviour rather than
requiring a diagnostic.
--
Flash Gordon
Mar 7 '07 #4

P: n/a

Flash Gordon wrote:
santosh wrote, On 07/03/07 03:49:
su**************@yahoo.com, India wrote:
Suppose the return type of main is void.

void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.
Yes. A diagnostic is required.

C&V? I know the standard specifies exactly two variants for main (and
allows the implementation to define more) but I don't believe that it is
in a constraint, so I think it is undefined behaviour rather than
requiring a diagnostic.
Flash, (and Keith), thanks for the correction. That's what happens
when you work too much with a single compiler, (gcc), and not read the
Standard carefully.

Mar 7 '07 #5

P: n/a
su**************@yahoo.com, India said:
Suppose the return type of main is void.
The return type of main is int. Supposing it is void is like supposing
the earth is a cube. It simply ain't so.
void main(void)
{
...

return;
}

Is the compiler supposed to generate warning or error according to
Standard C.
No, the compiler is under no obligation to diagnose an incorrect return
type, any more than it is obliged to diagnose i=i++ or fflush(stdin),
but void main is just as wrong as either of these.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 7 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.