Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: C/C++ link in TC++ Message-ID: <453@taumet.com> Date: 13 Sep 90 15:44:43 GMT References: <4800101@m.cs.uiuc.edu> <577@dptechno.UUCP> Organization: Taumetric Corporation, San Diego Lines: 46 cw@dptechno.UUCP (Charles Haden) writes: >In article <4800101@m.cs.uiuc.edu> reed@m.cs.uiuc.edu writes: ... >>I've attached a code sample below that fails when I do the following: >> tcc -c y.c >> tcc -c x.cpp y.obj >Your main problem lies primarily in the command line invocations >of the compiler. What I mean by that is your problem is not in >your source code it is in the way you are using the compiler. >As you should know from the manuals that you can compile both >"C" and "C++" source code with the compiler. What you probably >didn't read it that the compiler treats prototyping differently >based on the file extension ( default setting ). When compilling >a C++ source file, the function name is "tweaked" you might say >internally to allow for function overloading. This tweaking is >not normally done to standard C source code prototypes, since >overloading of function names is not allowed. There is a switch >however, that will force standard C source files to be tweaked >when compiling. This explanation is not really correct. Turbo C++ is really two compilers in one: it is a C compiler, and it is also a C++ compiler. In the absence of compiler flags, a file with an extension of ".CPP" will be compiled by the C++ compiler, and one with an extension of ".C" will be compiled by the C compiler. The "-P" flag forces ".C" files to be compiled by the C++ compiler. (I don't mean that there are necessarily two complete compilers hiding in one .EXE file, but that the behavior is as if there were two compilers.) C and C++ are different languages, and have some different rules. One C++ rule is that any function not declared extern "C" ... is expected to be a C++ function, and follows all C++ naming rules and calling conventions. If a function is declared so as to make it appear to be a C++ function, but is really a C function, the program can be expected to fail in some way. The most common way to fail (true for all current C++ systems I know of) is that the program will not link. The link failure is due to the different ways function names are treated in C and C++. The discussion in this paragraph is not unique to Turbo C++, but applies to any C++ implementation. -- Steve Clamage, TauMetric Corp, steve@taumet.com