This is the mail archive of the mailing list for the libstdc++ project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c_compatibility headers, include_next

Hey y'all. I have a cpp question, so I'm including the relevant folks,
with the hope that they'll be responsive.

What I'd like to do is ship a full set of "C" compatibility headers,
as per annex D of the C++ standard. These are things like <string.h>,
which include <cstring> and inject all the names in std:: into the
global namespace.

I've done this in my sandbox, but am having problems where:

/mnt/hd/ahimsa/bld-x86-gcc/gcc/g++ -B/mnt/hd/ahimsa/bld-x86-gcc/gcc/ -nostdinc++ -L/mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/src -L/mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/src/.libs -B/mnt/hd/ahimsa/H-x86-gcc/i686-pc-linux-gnu/bin/ -B/mnt/hd/ahimsa/H-x86-gcc/i686-pc-linux-gnu/lib/ -isystem /mnt/hd/ahimsa/H-x86-gcc/i686-pc-linux-gnu/include -ggdb3 -DDEBUG_ASSERT -ffunction-sections -fdata-sections -nostdinc++ -I/mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/i686-pc-linux-gnu -I/mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include -I/mnt/hd/bliss/src.gcc/libstdc++-v3/libsupc++ -I/mnt/hd/bliss/src.gcc/libstdc++-v3/libio -I/mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite /mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite/17_intro/ -DDEBUG_ASSERT -lm -o ./header_cstdio 
In file included from /mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/ctime:31,
                 from /mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/time.h:33,
                 from /usr/include/sys/types.h:126,
                 from /mnt/hd/bliss/src.gcc/libstdc++-v3/libio/_G_config.h:16,
                 from /mnt/hd/bliss/src.gcc/libstdc++-v3/libio/libio.h:30,
                 from /mnt/hd/ahimsa/bld-x86-gcc/gcc/include/stdio.h:73,
                 from /mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/bits/std_cstdio.h:42,
                 from /mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/cstdio:31,
                 from /mnt/hd/bliss/src.gcc/libstdc++-v3/testsuite/17_intro/
/mnt/hd/ahimsa/bld-x86-gcc/i686-pc-linux-gnu/libstdc++-v3/include/bits/std_ctime.h:57: `tm'
   not declared

The problem, in a nutshell, is that when <sys/types.h> in included, it
includes time.h and libstdc++'s "C" compatibility header <time.h> is
found and included, which then includes <ctime>, which includes
<usr/include/time.h>. The <ctime> header then expects that stuff like
struct tm will be declared and injects it into std like

namespace std
  using ::tm;

The problem is that when <sys/types> ends up including
</usr/include/time.h>, struct tm isn't declared (__need_tm or whatever
isn't defined, but more importantly the "C" standard doesn't require
it to be declared in this case...) and thus.......kableweeeeee.


This can be worked around by providing "C" compatibility headers for
just string.h and math.h, which are absolutely necessary as the C++
headers change "C" signatures or use builtins and thus #define away
required names from the global namespace to prevent overloading


The question is this: is there a way to structure the "C"
compabitility headers so that

#if (we're being included by an include_next'd header)
// use "C"
# include_next <foo.h>
// use c++
# include <cfoo>

I must be going mad to even consider this, but now I'm curious.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]