Prototype for main()

J

jaysome

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
 
S

santosh

jaysome said:
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.
 
E

Eric Sosman

jaysome said:
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().
 

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
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top