472,805 Members | 943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 9657

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Web Developer | last post by:
Hi, Comming from Java, it seems that prototype declarations are like abstract methods. I have not read classes in C++ yet, but prototype declarations are a strange concept. Any comments...
9
by: Neelesh | last post by:
Hi all, it is strange that the following code compiles and runs (tested with g++ 3.4.2) #include <iostream> using namespace std; int main(int a, int b, int c, int d, int e) { cout <<...
21
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am...
23
by: Allin Cottrell | last post by:
Thomas Heinz wrote (in re. gcc compilation of this erroneous program): $ cat test.c int f(int); int f(); int f() {return 0;} int main (void) { return 0; }
8
by: Chad Burggraf | last post by:
Hi all, I'm brand new to this newsgroup. I've been reading the FAQ's and some other documentation submitted by regulars of the group (such as "Javascript Best Practices" at...
3
by: mike_solomon | last post by:
I am trying to use prototype.js to log javascript errors among other things but by including <script type="text/javascript" src="prototype.js"></scriptin my page some of my existing javascript...
1
by: v4vijayakumar | last post by:
Can "c++ conversion operator" be considered as an example for Prototype design pattern? Following example explains, C++ conversion operator. #include <iostream> #include <string> using...
3
by: June Lee | last post by:
Is that for Class/Object function prototype, I must define the function in header file or .cpp file. MyClass::functionA(); MyClass::functionB(); but for C function prototype, I don't have to...
83
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.