[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what's the differnece between gcc and g++?

From: Rolf Magnus
Subject: Re: what's the differnece between gcc and g++?
Date: Sat, 02 Sep 2006 16:06:35 +0200 wrote:

> Hello, everyone,
> The difference between gcc and g++ puzzles me. Here "gcc" referes to
> the
> "gcc" command , not the GNU Compiler Collection.
> According to my study, "gcc" invoks  cc1plus under /usr/libexec/gcc/ ,
> and "g++" invokes cc1plus under /usr/libexec/gcc/.

> As C is a subset of C++,

You're wrong here. It is not.

> why we cannot use g++ alone to compile all C/C++ programs. 

Because there is no such thing as "C/C++". For the compiler, it's pretty
much irrelevant, as long as it has some way of knowing which language you
compile. gcc will try to gather that information from the file name, while
g++ will always try to compile the code as C++. Another way is to
explicitly specify the language to be compiled.
But linking is another story. When linking the result generated from C++
code, you need different linker options than for C code, and the linker
can't find out the language that the object code was compiled from, so you
have to tell it explicitly. When you use gcc for linking, it will pass the
options relevant for C code to the linker (unless you explicitly specify
the language), while g++ will link it as C++ code.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]