Phil Edwards pedwards@disaster.jaj.com
Wed Nov 1 14:21:00 GMT 2000

I wasn't going to bring this up for another week, but trying to fix the
getchar macro/decl collision is bringing this to a head.

We all know that the __cplusplus macro must be defined.  But ISO C++
requires that it have a value of 199711L (with the idea that future
standards use a later date, ergo a higher value; nothing new there).

Currently we just #define it, with no explicit value.  So it defaults
to 1.  This probably doesn't affect GNU systems, which are written to be
more-or-less standard in the first place.  But...

I changed the preprocessor to define __cplusplus to 199711L (it's a
two-line patch).  Life under Solaris went to hell in a padded handbasket.
The system include files are /crammed/ with constructs like this:

    #if __cplusplus >= 199711L
    namespace std {

    void a_standard_C++_function();

    #if __cplusplus >= 199711L

and C wrapper headers like

    #include <iso/stdio_iso.h>
    // contents of that header look like the previous example
    #if __cplusplus >= 199711L
    using std::FILE;
    using std::size_t;
    using std::printf;
    etc etc etc

This meant all kinds of ambiguity due to the using declarations suddenly
having an effect.  So I stopped looking at __cplusplus at the time.

For the getchar mess, the system header has

    #if __cplusplus >= 199711L
    namespace std {
        inline int getchar() { return getc(stdin); }
        inline int putchar(int _x) { return putc(_x, stdout); }
    #define getchar()   getc(stdin)
    #define putchar(x)  putc((x), stdout)
    #endif /* __cplusplus >= 199711L */

Adding the line "#undef getchar" to include/c/bits/std_cstdio.h results in

    [srcdir]/include/c/bits/std_cstdio.h:80: parse error before '--' token
    [srcdir]/include/c/bits/std_cstdio.h:83: parse error before '--' token
    [srcdir]/include/c/bits/std_cstdio.h:84: parse error before '--' token
    [srcdir]/include/c/bits/std_cstdio.h:94: parse error before "void"
    [srcdir]/include/c/bits/std_cstdio.h:95: parse error before '*' token
    [srcdir]/include/c/bits/std_cstdio.h:96: parse error before '*' token

(I have no idea what '--' it's talking about, but I haven't looked further.)

So, sometimes I feel that specifying the correct, ISO-mandated value for
__cplusplus now might help us.  But it might also cause a huge setback on
some systems.  It's going to be required eventually, but whether it should
push GCC 3.0 back even more...


pedwards at disaster dot jaj dot com  |  pme at sources dot redhat dot com
devphil at several other less interesting addresses in various dot domains
The gods do not protect fools.  Fools are protected by more capable fools.

More information about the Libstdc++ mailing list