This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ::gets has not been declared


On Thu, 5 Jan 2012, Marc Glisse wrote:

Do you have any suggestion on what libstdc++ can do when faced with C libraries that will randomly declare gets or not depending on flags? It would need knowledge of these exact flags so it can provide a replacement exactly when it isn't declared (or at least remove the using ::gets in that case, even if that is non-standard). The easiest workaround I can think of is to implement a failsafe version of using in the front-end, but there might be better solutions.

Maybe a C++03 version of some fancy template game like this?


#ifndef NOGETS
char* gets(char*){std::cout << "from libc\n";return 0;}
#endif

namespace Help1 {
struct Toobad{};
Toobad gets(...);
}
namespace Help2 {
using namespace Help1;
template<class T> struct A {
static const bool value=std::is_same<decltype(gets(std::declval<T>())),Help1::Toobad>::value && std::is_convertible<T,char*>::value;
};
}
template<class T> typename std::enable_if<Help2::A<T>::value,char*>::type gets(T x){ std::cout << "from libstdc++, call fgets\n";return 0; }



Certainly not completely legal, but might be close enough?


--
Marc Glisse


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