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

Prototype for main()

P: n/a
While looking at the source code for gcc today, I noticed that a
prototype for main() was declared. From gcc.c:

extern int main (int, const char **);

int
main (int argc, const char **argv)
{
....

I also noticed that several GNU utilities (e.g., gcov) also declare a
prototype for main().

The C standard says that, for main(): "The implementation declares no
prototype for this function". Did the GNU developers take that to mean
that the implementation declares no prototype for this function so you
must declare your own? I always thought that it is superfluous and
considered bad practice to declare such a prototype (especially in a
..c file, as in gcc.c).

Is there any reason why the gcc source code and other GNU utility
source code should declare a prototype for main()?

Regards
--
jay

Feb 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a

jaysome wrote:
While looking at the source code for gcc today, I noticed that a
prototype for main() was declared. From gcc.c:

extern int main (int, const char **);

int
main (int argc, const char **argv)
{
...

I also noticed that several GNU utilities (e.g., gcov) also declare a
prototype for main().

The C standard says that, for main(): "The implementation declares no
prototype for this function". Did the GNU developers take that to mean
that the implementation declares no prototype for this function so you
must declare your own? I always thought that it is superfluous and
considered bad practice to declare such a prototype (especially in a
.c file, as in gcc.c).

Is there any reason why the gcc source code and other GNU utility
source code should declare a prototype for main()?
Some non-conformant compilers complain when there's no prototype for
main. I think it's to shut these compiler up, that there's a prototype
for main. Also if main is called from someother module, a prototype
enables the compiler to do parameter checking.

Feb 22 '07 #2

P: n/a
jaysome wrote:
While looking at the source code for gcc today, I noticed that a
prototype for main() was declared. From gcc.c:

extern int main (int, const char **);

int
main (int argc, const char **argv)
{
...

I also noticed that several GNU utilities (e.g., gcov) also declare a
prototype for main().

The C standard says that, for main(): "The implementation declares no
prototype for this function". Did the GNU developers take that to mean
that the implementation declares no prototype for this function so you
must declare your own? I always thought that it is superfluous and
considered bad practice to declare such a prototype (especially in a
.c file, as in gcc.c).

Is there any reason why the gcc source code and other GNU utility
source code should declare a prototype for main()?
Unless main() is called recursively (from some module where
its definition is not visible), I cannot think of a reason to
write a separate declaration for it.

Just a guess: Perhaps at some time in the past, the sources
for these programs were run through a "Create declarations for
all externally-linked functions" utility. Such a utility might
not have had a special case to suppress a declaration for main().

--
Eric Sosman
es*****@acm-dot-org.invalid
Feb 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.