Return type of main()

  • Thread starter Christopher Benson-Manica
  • Start date
C

Chris Torek

What do you think of this argument that conforming programs may
declare main() as returning void?

http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html

A conforming C program may be written in Fortran, COBOL, or Ada;
so this is not much of an argument. :)

(A "conforming program" is anything accepted by a conforming
implementation, and implementations are free to accept random
rubbish, after issuing a required diagnostic if any. To eliminate
the syntax error you would normally get, use a "#pragma":

#pragma lispy
(defun main ...)

The above can be a conforming program.)
 
O

Old Wolf

Christopher said:
What do you think of this argument that conforming programs may
declare main() as returning void?

http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html

It seems to be a very long-winded explanation of the fact
that main() can be defined in an implementation-defined manner.

The reason 'void main()' is frowned on in this NG is, of course,
because relying on implementation-defined behaviour is non-portable.
For example, it may fail to compile on some conforming implementations.
 
J

Jack Klein

What do you think of this argument that conforming programs may
declare main() as returning void?

http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html

I personally agree with the author that allowing any other than the
two traditional definitions of main() in a hosted environment is a
poor choice.

In a discussion on comp.std.c, one of the committee members came up
with (IMNSHO) a rather wishy-washy explanation. It was along the
lines that if an implementation chooses to document that it accepts
such definitions as:

void main()

char *main()

FILE *main()

....or whatever, it is not free to excuse itself from other
requirements of the standard for an otherwise strictly conforming
program.

On the other hand, some of the examples are just plain wrong in what
they imply.

Visual C++, for example, claims conformance with the C standard as of
1995, which did not allow any additional implementation-defined
signatures for main(). Despite the fact that they probably state
somewhere in their documentation that they accept "void main()" in
addition to "int main()", it is a non-standard extension of undefined
behavior. As far as the C standard is concerned, Visual C++ has no
requirements all to meet when it accepts a C program starting with
"void main()".
 
S

Suman

Christopher said:
What do you think of this argument that conforming programs may
declare main() as returning void?

http://homepages.tesco.net/~J.deBoynePollard/FGA/legality-of-void-main.html
I really did like this line :)
"So if one's compiler's documentation happens to say anywhere that main
may have the return type void then main may indeed have the return type
void and a program with void main() is a conforming program"
Though in his hubris he seems to have missed out on the following
"for that paricular system".
Regards,
Suman.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top