gets with C++ and GCC before 4.7

Jonathan Wakely jwakely.gcc@gmail.com
Sat Mar 10 01:54:00 GMT 2012


On 9 March 2012 20:57, Joseph S. Myers wrote:
>
> Feature-test macros are outside the scope of ISO C++.  But _GNU_SOURCE is
> always defined by GCC when compiling C++ code, because libstdc++ needs
> functionality from the C library that's outside pure ISO C and C++, so
> there is no way to tell whether the user wanted the strict ISO C++ library
> or the GNU variant

Right. I don't speak for the other libstdc++ maintainers but I'd be
completely happy with gets() not being declared when the user defines
_GNU_SOURCE, as opposed to G++ defining it automatically, but there's
no way to tell the difference.

> - and developing a way to make the relevant
> functionality visible to libstdc++ in a namespace-clean way, so that a
> user can choose what becomes visible from the C library, would certainly
> be a substantial project.

I would love it if there was something like a _GLIBCXX_SOURCE macro
that gave us the glibc extensions we rely on, so G++ didn't need to
define _GNU_SOURCE.  Currently we don't have that and not only would
it probably make the glibc code messier but just adding it to glibc
wouldn't help if a new glibc was used with an old GCC that still
expected to be able to use _GNU_SOURCE to expose the required
functionality.  I'm sure there are better solutions but maybe glibc
could handle that with something like:

#if defined(__cplusplus) && defined(_GNU_SOURCE)
#if (__GNUC__*100+__GNUC_MINOR__) < 408
#define _GLIBCXX_SOURCE
#endif
#endif


Anyway, thanks for the fix, Joseph.



More information about the Libstdc++ mailing list