Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 14th, 2007, 3:46 AM   #1
sharadpro
Newbie
 
Join Date: Feb 2006
Location: India
Posts: 25
Rep Power: 0 sharadpro is on a distinguished road
Return type - main() / ISO C standard

The ISO C++ standard clearly wants the return type of main to be int, so there is no conflict there.But quoting from the link given below,ISO C standard doesn't say so :

Quote:
The ISO C++ Standard (ISO/IEC 14882:1998) specifically requires main to return int. But the ISO C Standard (ISO/IEC 9899:1999) actually does not. This comes as a surprise to many people. But despite what many documents say, including the Usenet comp.lang.c FAQ document (at great length), the actual text of the C Standard allows for main returning other types.
http://homepages.tesco.net/J.deBoyne...void-main.html

I completely understand that void main() is EVIL anyways but please clarify the issue as per the C standard!
sharadpro is offline   Reply With Quote
Old Mar 14th, 2007, 4:16 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3 Jimbo is on a distinguished road
From some draft of the standard I have in PDF form:
Quote:
1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;(9) or in some other implementation-defined manner.
.....
(9) Thus, int can be replaced by a typedef name defined as int, or the type of argv can be written as
char ** argv, and so on.
The actual standard might be slightly revised, but I'm almost certain the return type of main still has to be compatible with int.
__________________
<insert disclaimer here>
<insert shameless plug for Visual Studio here>
Jimbo is offline   Reply With Quote
Old Mar 14th, 2007, 6:02 AM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
There are some people who quibble over the placement of a semi-colon in the C standard, claiming that the way it is placed allows main() to be implemented in ways other than returning int. The people who do that are attempting to say that main() not returning int is still standard C. They are talking from their nether regions.

The C and C++ standards are worded differently (mainly because the C++ standard has to be unambiguous and prevent things like overloading of main() by a programmer). However, both are quite clear in requiring compilers to support main() in both the "int main()" and "int main(int argc char *argv[])" [or equivalent] forms, and that any other form of main() is implementation defined behaviour.

Which means that both C and C++ compilers are required to support the int main() forms, or they cannot be described as standard compliant. Other forms represent implementation defined behaviour: a compiler is allowed to support any form of main() it wishes as long as it also supports the two int forms.

User code, on the other hand, cannot be compliant with the standard if it uses any form of main() other than the int forms. In english, this means that code which uses any form of main, other than the two int forms, is compiler specific.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C# corruption!!! Kilo C++ 32 May 21st, 2006 8:44 PM
OOT Program Examples Sane Other Scripting Languages 4 Nov 25th, 2005 12:06 AM
using `char' return type in functions atreyu C 6 Jul 22nd, 2005 12:13 PM
Pointers in C (Part I) Stack Overflow C 4 Apr 28th, 2005 7:03 PM
function solomon_13000 Java 6 Apr 2nd, 2005 11:42 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC