As you'll see, I went ahead and committed the patch you sent. After reading about why gcc has done this and the ISO C++ standard, I think I like your first patch the best. We will have to get some people to try compiling with other C++ compilers and see if it breaks anything (but my guess is it shouldn't). Even my Stroustrup book shows your code to be good and it was the definitive on the language when most compilers were designed.

David

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


--
.............................................................................
David L. Thompson                   Visualization and Imagery Solutions, Inc.
mailto:[EMAIL PROTECTED]    5515 Skyway Drive, Missoula, MT 59804
                                    Phone : (406)257-8530

Reply via email to