473,396 Members | 1,713 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,396 software developers and data experts.

Who calls main() in C++ programs

44
Hi,

This is abhinay,
I always suffered with following questions,
I red many docs but I could't gets its proper answer,
if u can help me then plz......
thanks in advance.

My questions are:

1. Which code or process is responsible for first call to main() in C/C++ programs.?

2. main() is user defined function still why main() is geting called first. ?

3. Which doc should i read for detailed information.

Thanks
Abhinay
May 2 '07 #1
2 3594
JosAH
11,448 Expert 8TB
Hi,

This is abhinay,
I always suffered with following questions,
I red many docs but I could't gets its proper answer,
if u can help me then plz......
thanks in advance.

My questions are:

1. Which code or process is responsible for first call to main() in C/C++ programs.?

2. main() is user defined function still why main() is geting called first. ?

3. Which doc should i read for detailed information.

Thanks
Abhinay
1: The code that starts running first is the 'startup code'. Traditionally it's called
'c0' (unixes) or 'crt0' (MS windows). The code does some initialization work
and then basically performs this action:
Expand|Select|Wrap|Line Numbers
  1. exit(main(...));
i.e. it takes the return value of main and returns the completion status back to
the os again (which called c0 or crt0).

2: The startup code expects your code to supply a main() method.

3: any good book or manual for C/C++ compilers should give you all the info.
If you're working on a unix platform check the man pages.

kind regards,

Jos
May 2 '07 #2
svlsr2000
181 Expert 100+
You can have look at how linkers and loaders work.
http://www.linuxjournal.com/article/6463
Its not always necessary to have a main, the compiler i use has a option of setting the entry function.
May 2 '07 #3

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

Similar topics

1
by: maya2000 | last post by:
Hi, I am trying to open multiple Java3D windows from my application. I want to open each window when I select a checkboxmenu. Follwoing code doesn't show me the Java3D windows, so how can I make...
3
by: Charles Hartman | last post by:
I know the answer to this is going to be "It depends . . .", but I want to get my mind right. In Fowler's *Refactoring* I read: "Older languages carried an overhead in subroutine calls, which...
12
by: jrefactors | last post by:
If the C programs have UNIX system calls such as fork(), alarm(), etc.., we should call it UNIX programs, not traditional C programs? We couldn't compile the programs with system calls using VC++...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
5
by: Seong-Kook Shin | last post by:
Hi, I'm reading Steve's "C Programming FAQs" in book version, and have two question regarding to Q11.16 ... Also, a `return' from `main' cannot be expected to work if data local to main might be...
11
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
21
by: omkar pangarkar | last post by:
Hi all, I have two simple hello world programs one using printf() and other using write() --prog 1-- #include<stdio.h> #include<stdlib.h> int main() { printf("Hello"); /* up to here...
20
by: David Mathog | last post by:
For this small test program: #include <stdio.h> void main(void){ char buffer="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; int size, count; size = 27; /* always a small number which will fit in an int */...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.