rhys@batserver.cs.uq.oz.au (Rhys Weatherley) (11/27/90)
The subject should say it all :-). Basically, Turbo C++ has the macro __cplusplus which is defined when Turbo C++ is compiling using C++ conventions. This macro is handy for importing "standard C" routines by "wrapping up" their prototypes and definitions, etc in the following form: #ifdef __cplusplus extern "C" { #endif ... Plain ordinary C declarations and code ... #ifdef __cplusplus } #endif The 'extern "C"' declaration also appears to work in G++ (although I haven't tried __cplusplus yet), but mainly I'm asking if a standard ANSI or pre-ANSI macro does exist for this purpose. Is it __cplusplus, or something different, or isn't there one at all? This is of concern to me since I'm on a huge "portability drive" at the moment. So much for "dumb question number 437", but I'm sure lots of "portability freaks" out there would also be interested. Rhys. P.S. I didn't post to comp.std.c++ because different compilers may have different ways of doing this operation, which are "not standard". +===============================+==============================+ || Rhys Weatherley | University of Queensland, || || rhys@batserver.cs.uq.oz.au | Australia. G'day!! || +===============================+==============================+
jbuck@galileo.berkeley.edu (Joe Buck) (11/28/90)
In article <5954@uqcspe.cs.uq.oz.au>, rhys@batserver.cs.uq.oz.au (Rhys Weatherley) writes: > The subject should say it all :-). Basically, Turbo C++ has the macro > __cplusplus which is defined when Turbo C++ is compiling using C++ conventions. Yes, __cplusplus is part of the draft language standard. Enter broken record mode: Professional C++ programmers should have a copy of "The Annotated C++ Reference Manual" by Ellis & Stroustrup, which answers all questions like these. Exit broken record mode. extern "C" is also part of the standard. No compiler really agrees with E&S in all respects (probably cfront 2.1 comes closest, but I haven't used it). If your compiler disagrees with E&S, complain to the vendor or mail a bug report. -- Joe Buck jbuck@galileo.berkeley.edu {uunet,ucbvax}!galileo.berkeley.edu!jbuck
jimad@microsoft.UUCP (Jim ADCOCK) (12/06/90)
In article <5954@uqcspe.cs.uq.oz.au> rhys@batserver.cs.uq.oz.au writes: >The subject should say it all :-). Page 383 of "The Annotated C++ Reference Manual" [Ellis & Stroustrup, Addison-Wesley, 1990 ISBN 0-201-51459-1] states that __cplusplus will be defined for all C++ implementations -- even those still using "Classic C" preprocessors. Page 379 states also that _cplusplus is defined -- when compiling C++ programs. The implication in my mind is that if one has a compiler smart enough to compile both C++ and "Classic C" programs, either noting the difference via compilation flags, filename extensions, or whatever, then __cplusplus is defined only in the C++ compilation case. IE this decision is made based on the flavor of the compilation, not the flavor of the compiler. Identical language is used in the working papers of the ANSI-C++ committee, and I believe __cplusplus is well supported in practice by actual C++ compilers.