473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

main problem

dear friends plz clarify my doubt
we know that there are three aspects regarding function
1.function declaration
2.function call
3.function definition
in c,c++ program at the start we write
main()
{
...;
...;
}
now my question is
is this a function declaration or definition or calling?
if it is a function call why don't we give semicolon after main
since often we write function call as
Ex.
swap();
add();
then why not main();
Jan 13 '07 #1
5 1269
Banfa
9,065 Expert Mod 8TB
this is a function definition. The function call is made from with-in the c-start-up code provided by the compiler writer. I do not think that main is declared anywhere.
Jan 13 '07 #2
Ganon11
3,652 Expert 2GB
From what I know of the subject, the main reason for a function declaration is to let your compiler know that the function exists. If you didn't declare a function, but still had the definitions somewhere below your main, the compiler may get confused and not recognize these functions when it tries to compile main(). I'm not sure, but I think you could replace the function declarations at the beginning of your program with the full definition, so that the main() function recognizes its existance and already has the code.
Jan 13 '07 #3
this is a function definition. The function call is made from with-in the c-start-up code provided by the compiler writer. I do not think that main is declared anywhere.
THANKS FOR THE REPLY.
you mentioned that main is not declared.
i agree with you in case of C .
As in C function declaration is optional but as far as C++ is concerned
function declaration is must.
so how it is possible for compiler to compile program without declaration of function in C++.
Jan 13 '07 #4
From what I know of the subject, the main reason for a function declaration is to let your compiler know that the function exists. If you didn't declare a function, but still had the definitions somewhere below your main, the compiler may get confused and not recognize these functions when it tries to compile main(). I'm not sure, but I think you could replace the function declarations at the beginning of your program with the full definition, so that the main() function recognizes its existance and already has the code.
THANKS FOR THE REPLY.
you mentioned that main is not declared.
i agree with you in case of C .
As in C function declaration is optional but as far as C++ is concerned
function declaration is must.
so how it is possible for compiler to compile program without declaration of function in C++.

--------------------------------------------------------------------------------
Jan 13 '07 #5
Banfa
9,065 Expert Mod 8TB
It is possible because the piece of code that calls main is not (normally) released to you as source code (except for reference) but is realeased precompiled as binary code. The definition is only required for compilation of the function call not the function definition.

I have checked my MSVC++ installation and main is predeclared, but only in an internal header that appears to be only included into library source code.


The rule is C++ is not that a function must be predeclared. It is that a function can't not be called before it has been defined or predeclared. Which is subtly different.
Jan 13 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
19
by: Steven T. Hatton | last post by:
The short sample program listed below has some features that I find to be bad style. In particular, they fail to communicate the connection between names used in this program and the location in...
13
by: Sokar | last post by:
I have my main function set up as int main(int argv, char *argv) so taht i can read in a variable which is passed to the program on the command line. The problem is that main calls other...
9
by: CSharpNewBie | last post by:
Hi I am creating a Winform application and I need help. Let me explain my problem This is what i do on startup, I create a form (a Login screen) at runtime and that will ask user to enter a...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
11
by: Jim | last post by:
Hi, I have created an import module. And would like to access a function from the main script, e.g., file abc.py: ################### def a(): m() return None
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
3
by: suva | last post by:
Hi, What is the precise problem for which we cant declare main() as static. I know there is no reason to do so but still I wish to know the precise technical problem for which it is disallowed.
37
by: nick | last post by:
Does anyone know the file where the main function is defined? thanks
1
by: Bill Woodruff | last post by:
Visual Studio 2005, .NET FrameWork 2.0, C#, WinForms Application Hi, I've read the recent posts by and to 'Thunderbird' (and learned a lot, thanks, from the usual masters Skeet and Paladino,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.