Re: C++ linking v.s. C (David Fletcher)
20 Dec 1995 11:38:48 -0500

          From comp.compilers

Related articles
C++ linking v.s. C (1995-12-19)
Re: C++ linking v.s. C (1995-12-20)
| List of all articles for this month |

From: (David Fletcher)
Newsgroups: comp.compilers
Date: 20 Dec 1995 11:38:48 -0500
Organization: Hewlett Packard - Ft. Collins
References: 95-12-115
Keywords: C, C++, linker (Nathan A. Yoffa) writes:
> My question is the folllowing: To what degree does using CC
> for this link produce different code (if any).....

and the moderator noted:
> Every C and C++ compiler I know use a common linker. I'd be
> astonished if the code changed, though it's possible you might
> find yourself using C++ libraries where you used to use C
> libraries.

Note that with (many) cfront-based C++ compilers you have to make sure
that the main() routine is compiled with the C++ compiler. This is
needed so that static/global constructors and destructors get called.
Basically, the C++ compiler renames the original main() routine to
_main(), and then adds a new version of main() similar to the

int main(int arc, char** argv, char** envp)
// ... code to call static/global constructors goes here...
int ReturnVal = _main(argc, argv, envp);
// ... code to call static/global destructors goes here...
return ReturnVal;

As long as you do not include anything that has a static/global
constructor or destructor your code should be fine (apart from the
fact that, on some systems, the run-time libraries are different from
those used with plain ol' C --- these differ with less frequency on
modern systems).

Hope this helps.
David Fletcher
ESL, Hewlett-Packard
Ft. Collins, CO
1.970.229.4970 (voice)

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.