Daniel Kobras wrote:
On Wed, Oct 23, 2002 at 10:32:56AM -0600, David Thompson wrote:

I looked through your attached patch and have a couple of questions. I understand the problems with the headers stream.h versus stream and would add those patches, but what is up with needing to add the standard namespace to methods? Is there some new ANSI document that the GCC group is following to make not including it an error?


gcc 3.x follows ISO C++ here.

Regards,

Daniel.



Exactly. This means that this code is rejected

#include <iostream>
int main(void) {
        cout << "hello" << endl;
        return 0;
};

while these versions are legal

1)
#include <iostream>
int main(void) {
        std::cout << "hello" << std::endl;
        return 0;
};

2)
#include <iostream>
using namespace std;
int main(void) {
        cout << "hello" << endl;
        return 0;
};

3)
#include <iostream>
using std::cout;
using std::endl;
int main(void) {
        cout << "hello" << endl;
        return 0;
};

Version 1) is in the current patch. I think version 2)
is ill-advised, while version 3) could be a good compromise between
portability and namespace encapsulation. If you don't like solution 1)
I was thinking to add something like

dnl ----------------------------------------------------------------
dnl
dnl Check for std namespace
dnl

AC_LANG_CPLUSPLUS
AC_MSG_CHECKING([whether the C++ compiler allows to use namespace std])
AC_TRY_COMPILE([
        #include <iostream>
        using std::cout;
],[
        cout << "a";
],[allow_std=yes],[allow_std=no])
if test $allow_std != no ; then
        AC_DEFINE(USING_STD,1,[define if C++ compiler allows namespace std])
        AC_MSG_RESULT([yes])
else
        AC_MSG_RESULT([no])
fi
AC_LANG_C
dnl ----------------------------------------------------------------


in configure.ac

and then wrap everything:

#include <iostream>
#include <dxconfig.h>
if defined(USING_STD)
using std::cout;
using std::endl;
#endif

int main(void) {
        cout << "hello" << endl;
        return 0;
};


Do you think this solution could be ok?

Marco Morandini

Reply via email to