Topic: Is __cplusplus gone?


Author: cbarber@es1.boston.deshaw.com (Christopher Barber)
Date: 1996/08/27
Raw View
In the documentation for g++ predefined macros is the following:

  `__cplusplus'
     The draft ANSI standard for C++ used to require predefining this
     variable.  Though it is no longer required, GNU C++ continues to
     define it, as do other popular C++ compilers.  You can use
     `__cplusplus' to test whether a header is compiled by a C compiler
     or a C++ compiler.

Is it true that __cplusplus is no longer required?  If so, then:
   (1) What is the rationale for this?
   (2) Is it replaced by some other macro?
   (3) How can we write header files for use in both C and C++.

- Chris
--
Christopher Barber ----- Software Engineer ---- D.E.Shaw & Co.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: vandevod@cs.rpi.edu (David Vandevoorde)
Date: 1996/08/27
Raw View
>>>>> "CB" == Christopher Barber <cbarber@es1.boston.deshaw.com> writes:
[...]
CB> Is it true that __cplusplus is no longer required?
[...]

No. This is from the post Santa Cruz DWP ([cpp.predefined] 16.8/1)

 __cplusplus
     The  name __cplusplus is defined to the value 199711L when
     compiling a C++ translation unit.7)

I believe this number is large enough to guarantee that the value of
__cplusplus is larger than those of __just_c, __java, __eiffel and
several other dubious names.

Ah yes, there is a footnote on this thing:

 7) It is intended that future versions of this standard will
    replace the  value of this macro with a greater value.
    Non-conforming compilers should use a value with at most
    five decimal digits.

The number is supposed to indicate the expected standardization date
(i.e., the value above will be increased at a later X3J16/WG21 meeting).

 Daveed


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1996/08/27
Raw View
Hi,
Christopher Barber (cbarber@es1.boston.deshaw.com) wrote:
: In the documentation for g++ predefined macros is the following:

:   `__cplusplus'
:      The draft ANSI standard for C++ used to require predefining this
:      variable.  Though it is no longer required, GNU C++ continues to
:      define it, as do other popular C++ compilers.  You can use
:      `__cplusplus' to test whether a header is compiled by a C compiler
:      or a C++ compiler.

: Is it true that __cplusplus is no longer required?

No. Here is an excerpt from the DWP:

    16.8  Predefined macro names                          [cpp.predefined]

  1 The following macro names shall be defined by the implementation:

    [...]

    __cplusplus
      The  name __cplusplus is defined to the value 199711L when compiling
      a C++ translation unit.7)

    [...]
    _________________________
    7) It is intended that future versions of this standard  will  replace
    the  value of this macro with a greater value.  Non-conforming compil
    ers should use a value with at most five decimal digits.

The value will probably *NOT* be the one found above but rather the
date when the standard was accepted.

BTW, note that the "non-conforming" clause will probably be useless:
There cannot be any restrictions imposed on a not conforming compiler
(otherwise it would have to conform to something). Thus, you can rely
on its use only for conforming compilers.  In analogy, I remember a
non-conforming C compiler (i.e. not conforming to the ANSI/ISO C
standard) which had __ANSI__ defined! It basically broke every code
which was written to handle both ANSI and K&R C :-(
--
<mailto:dietmar.kuehl@uni-konstanz.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]