473,385 Members | 1,372 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.

difference between main function of c and c++

hi
what is the difference between the main() function of c and c++
Aug 30 '08 #1
4 3450
pankaj do it wrote:
what is the difference between the main() function of c and c++
There is no difference. Both have the same signature. Both use C linkage.
Marcel
Aug 30 '08 #2
On Aug 30, 4:48 pm, Marcel Müller <news.5.ma...@spamgourmet.org>
wrote:
pankaj do it wrote:
what is the difference between the main() function of c and c++
There is no difference. Both have the same signature. Both use
C linkage.
In C++, the linkage of main is implementation defined. It might
be "C++", it might be "C" or it might be something else
entirely.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Aug 31 '08 #3
James Kanze wrote:
On Aug 30, 4:48 pm, Marcel Müller <news.5.ma...@spamgourmet.org>
wrote:
>pankaj do it wrote:
what is the difference between the main() function of c and c++
>There is no difference. Both have the same signature. Both use
C linkage.

In C++, the linkage of main is implementation defined. It might
be "C++", it might be "C" or it might be something else
entirely.
Isn't this largly determined by the startup code as a practical matter?
If so, it seems that basically it's implementation defined even in c.

It's probably just a personal limitation, but I can't imagine a reason
to call main from anything other than startup code. Seems like
any attempt to do so would need to diddle implementation defined
environment stuff to be effective. To use Kernighan's phrase, am I
suffering from a "poverty of imagination"?
Aug 31 '08 #4
On Aug 31, 9:34 pm, stan <smo...@exis.netwrote:
James Kanze wrote:
On Aug 30, 4:48 pm, Marcel Müller <news.5.ma...@spamgourmet.org>
wrote:
pankaj do it wrote:
what is the difference between the main() function of c and c++
There is no difference. Both have the same signature. Both use
C linkage.
In C++, the linkage of main is implementation defined. It might
be "C++", it might be "C" or it might be something else
entirely.
Isn't this largly determined by the startup code as a
practical matter? If so, it seems that basically it's
implementation defined even in c.
Formally, the C++ or C program doesn't start until main has been
reached, but practically, yes... an implementation will
obviously have to define main in some way that it can be called
via the start-up code. (But of course, the start-up code is
part of the implementation.) As another poster pointed out, C
also allows main to be called (recursively) from within the
program, which introduces some additional constraints on it.
It's probably just a personal limitation, but I can't imagine
a reason to call main from anything other than startup code.
There are some interesting examples of using main recursively in
the IOCCC, but that's about it as far as I'm concerned as well.
Seems like any attempt to do so would need to diddle
implementation defined environment stuff to be effective. To
use Kernighan's phrase, am I suffering from a "poverty of
imagination"?
I can imagine any number of special things you could do by
calling main recursively. In every case, however, I can also
imagine a solution which wouldn't involve calling main
recursively which would be considerably more understandable and
easier to maintain.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 1 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nimmi Srivastav | last post by:
Once and for all can someone kindly tell me the difference between C and C++ linkage. I thought I understood it till someone showed me the other day that C functions, that would ordinarily require...
7
by: wwj | last post by:
Hi ,all I want to know the difference between char a and char *p=new char and the difference between the heap and the stack ,and if the char a is corresponding to the stack in MEMORY,and char...
9
by: jlopes | last post by:
I'm looking at the differences between these to forms and see no difference in their use. When accessed through a derived class. class ABase { public: virtual void filter(){ /* some code */ }...
17
by: ambar.shome | last post by:
Can anyone tell me : 1. void main() { char temp = "Hello"; temp='K';
5
by: QQ | last post by:
I know there are many functions that I can exit the program such as return 0, exit(0), exit(1),_EXIT(0) .... What are the difference between them? Thanks a lot!
17
by: jwaixs | last post by:
Hello, I was wondering, what's the difference between exit and return in the main() function? For me they both look the same, or aren't they? And if they aren't, which should I use in which...
12
by: z. f. | last post by:
what's the difference between using the VB.NET function IIF or the c# operator ? VB.NET: a = iif ( b=c, d, e) C#: a= (b==c)?d:e TIA, z.
5
by: Antonio Parolini | last post by:
What is the difference between: main(......) { exit(0); } and main(......) {
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
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...

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.