Mental Patient on 8 Oct 2003 16:49:02 -0000


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

Re: [PLUG] gcc vs cc vs c++


Kyle R. Burton wrote:
gcc/cc treats the source code as C, where that syntax involving cout
means something (very) different (left-shift).  g++/c++ treats the
source code as C++ where operator overloading on the cout object (an
ostream) makes the left-shift operation mean something completely
different (equivalent to a function call, like write).

The link error is related to the default libraries that are linked in,
for gcc/cc it's just libc (and maybe some others).  For g++/c++ it should
include libstdc++ (which is where cout and other things live).


To follow up on this, its the same compiler. Its just that when you invoke gcc as g++, as Kyle points out, it goes into C++ mode. You can use gcc as gcc if you specify the language and link with the appropriate librarys. For the simple example of:


#include <ostream.h>

int main()
{
  cout << "Hello, World" << endl;
  return 0;
}

You could compile this with either:

g++ foo.cpp

or

gcc -std=gnu++98 -lstdc++ foo.cpp

I'd recomnend not doing the latter. C++ is sufficiently complex that there are good reasons for g++ to exist.

--

Mental (Mental@NeverLight.com)

"The Torah...  The Gospels...  The Koran...
Each claimed as the infallible word of GOD.
Misquoted, misinterpreted, misunderstood, and misapplied.
Maybe that's why he doesn't do any more interviews." - sinfest.net

CARPE NOCTEM, QUAM MINIMUM CREDULA POSTERO.

GPG public key: http://www.neverlight.com/pas/Mental.asc


Attachment: pgptgqfXd4UmX.pgp
Description: PGP signature