This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Strange behaviour of strchr in C++
Mateusz Åoskot wrote:
> > By the way, should it be reported to libstdc++ bugzilla?
On Tue, Feb 28, 2006 at 01:24:56AM +0100, Paolo Carlini wrote:
> I don't think so, really. The problem (and its relatives) is very well
> known, basically is subsumed by libstdc++/6257. Also, AFAIK, there are
> hopes that the next standard will make the life easier to the
> implementors wrt this kind of issues.
It might be possible to fix this issue without fixing all of 6257.
A <cstring> that does not include <string.h>, but that provides the
correct declarations, together with code to implement the two C++
strchr's as the C strchr with appropriate const_casts, would do the
job. The current problem is that <cstring> contains <string.h>.
This could be extended to a partial fix for 6257 as a whole: the C
names would remain in the global namespace, but their global namespace
declarations would not appear in the standard headers. For example,
we'd have declarations for std::printf, and appropriate magic so
that it is linked to the C printf global.
This leaves the problem that ISO C++ lets someone write
----------------
#include <cstdio>
// printf is not reserved, I can define it.
int printf = 42;
int main() {
std::printf("The answer is %d\n", printf);
}
----------------
One possibility might be a kind of "swap". For the C standard names,
C++ name Linker name
std::printf => printf
::printf => __BLAH_printf
(Replace BLAH by something appropriate). That is, swap the roles
of std:: and the global namespace for the standard C symbols that
ISO requires that C++ provide in the std:: namespace.
An issue is that this changes the ABI. However, it might be that this
doesn't matter (if only programs that are problematic right now
are affected).