This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15415] _REENTRANT defined if string header included without -pthread
- From: "cludwig at cdc dot informatik dot tu-darmstadt dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 13 May 2004 12:46:29 -0000
- Subject: [Bug c++/15415] _REENTRANT defined if string header included without -pthread
- References: <20040513100538.15415.cludwig@cdc.informatik.tu-darmstadt.de>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From cludwig at cdc dot informatik dot tu-darmstadt dot de 2004-05-13 12:46 -------
Subject: Re: _REENTRANT defined if string header included without -pthread
On Thu, May 13, 2004 at 10:53:29AM -0000, pinskia at gcc dot gnu dot org wrote:
> This is a dup of bug 11953,
I don't know why I missed #11953. Sorry.
> this was an intended change.
Very well, but I doubt the consequence I complained about (not beeing
able to detect -pthread on x86 / Linux) was intended... Note that the
patch that introduced this change was supposed to solve a problem on
True64 Unix, http://gcc.gnu.org/ml/gcc-patches/2003-07/msg01607.html
does not talk about x86 / Linux at all.
But more important: The solution to #11953 proposed by Benjamin Kosnik
(test for _POSIX_THREADS and check >=0) fails! If I amend my test and
compile it with gcc 3.4.0, I get the following:
cludwig@lap200:~/C++/gcc3.4/tmp> cat REENTRANT.cc
#if defined(INCLUDE_STRING)
# include <string>
# warning "string header included"
#else
# warning "no header included"
#endif
#if defined(_REENTRANT)
# warning "_REENTRANT is defined"
#else
# warning "_REENTRANT is not defined"
#endif
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
# warning "_POSIX_THREADS >= 0"
#elif defined(_POSIX_THREADS)
# warning "_POSIX_THREADS defxined"
#else
# warning "_POSIX_THREADS not defined"
#endif
#include <unistd.h>
#warning "After inclusion of unistd.h:"
#if defined(_REENTRANT)
# warning "_REENTRANT is defined"
#else
# warning "_REENTRANT is not defined"
#endif
#if defined(_POSIX_THREADS) && _POSIX_THREADS >= 0
# warning "_POSIX_THREADS >= 0"
#elif defined(_POSIX_THREADS)
# warning "_POSIX_THREADS defxined"
#else
# warning "_POSIX_THREADS not defined"
#endif
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:11:4: Warnung: #warning "_REENTRANT is not defined"
REENTRANT.cc:19:4: Warnung: #warning "_POSIX_THREADS not defined"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:29:4: Warnung: #warning "_REENTRANT is not defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
cludwig@lap200:~/C++/gcc3.4/tmp> g++ -DINCLUDE_STRING -o /dev/null -c REENTRANT.cc
REENTRANT.cc:3:4: Warnung: #warning "string header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:15:4: Warnung: #warning "_POSIX_THREADS >= 0"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:27:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
ludwig@lap200:~/C++/gcc3.4/tmp> g++ -pthread -o /dev/null -c REENTRANT.cc
REENTRANT.cc:5:4: Warnung: #warning "no header included"
REENTRANT.cc:9:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:19:4: Warnung: #warning "_POSIX_THREADS not defined"
REENTRANT.cc:24:2: Warnung: #warning "After inclusion of unistd.h:"
REENTRANT.cc:27:4: Warnung: #warning "_REENTRANT is defined"
REENTRANT.cc:33:4: Warnung: #warning "_POSIX_THREADS >= 0"
_POSIX_THREADS is defined only if certain headers are included. It
does not matter at all if -pthread was on the compilers command line.
It seems to me (without looking up any references) that _POSIX_THREADS
indicates whether the *system* offers pthread support. But it's
totally useless if you want to decide whether the current translation
unit is to be built with thread support. (After all, I don't want to
pay for any overhead in a single threaded application, even if both
the compiler and the system are capable of pthread support.)
I therefore don't consider this bug report as resolved yet. There is
no documented way to decide at compile time whether -pthread was on
the command line.
Regards
Christoph
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15415