[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: Paul Pluzhnikov
Subject: Re: what's the differnece between gcc and g++?
Date: Fri, 25 Aug 2006 22:50:34 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) writes:

> According to my study, "gcc" invoks  cc1plus under /usr/libexec/gcc/ ,
> and "g++" invokes cc1plus under /usr/libexec/gcc/.

'gcc' will invoke different compiler depending on the file extension,
and other command line arguments.

For example:

  echo "int main() { return 0; }" > junk.c && ln junk.c junk.cpp
  gcc -c junk.c        # invokes 'cc1'
  gcc -c junk.cpp      # invokes 'cc1plus'
  gcc -c -xc junk.cpp  # 'cc1'
  gcc -c -xc++ junk.c  # 'cc1plus'

The exact location where 'cc1' etc. come from also depends on how
gcc was configured, and command line flags, such as -B.

Finally, at link time 'g++' links libstdc++, and 'gcc' doesn't.

> As C is a subset of C++, 

C is not a proper subset of C++: many programs that are valid C
are not valid C++, and vice versa.

Here is a trivial example:

$ echo "int main() { free(malloc(1)); return 0; }" > junk.c
$ gcc -c junk.c && echo ok

$ g++ -c junk.c && echo ok
junk.c: In function `int main()':
junk.c:1: error: `malloc' undeclared (first use this function)
junk.c:1: error: (Each undeclared identifier is reported only once for each 
   function it appears in.)
junk.c:1: error: `free' undeclared (first use this function)

In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.

reply via email to

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