469,964 Members | 1,455 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

Prototype for main()

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
2 9502

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
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.

Similar topics

5 posts views Thread by Web Developer | last post: by
9 posts views Thread by Neelesh | last post: by
21 posts views Thread by Rob Somers | last post: by
23 posts views Thread by Allin Cottrell | last post: by
8 posts views Thread by Chad Burggraf | last post: by
3 posts views Thread by mike_solomon | last post: by
1 post views Thread by v4vijayakumar | last post: by
3 posts views Thread by June Lee | last post: by
83 posts views Thread by liketofindoutwhy | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.