[Pkg-ace-devel] Bug#380739: boost compiles differently,
if ACE header is included first
Thomas Girard
thomas.g.girard at free.fr
Wed Aug 2 21:16:48 UTC 2006
tags 380739 + upstream
thanks
Hello Torsten,
On Tue, Aug 01, 2006 at 11:27:19AM +0200, Harling, Torsten wrote:
> #include <boost/shared_ptr.hpp>
> #include <ace/OS.h>
> #include <iostream>
>
> using namespace std;
>
> int main (int argc, char **argv)
> {
> cout << "sizeof (boost::detail::sp_counted_base) == "
> << sizeof (boost::detail::sp_counted_base) << endl;
> }
>
> Ouputs:
> sizeof (boost::detail::sp_counted_base) == 12
>
> Now including the ace header first (only the order of
> the include files is changed) ouputs:
> sizeof (boost::detail::sp_counted_base) == 36
>
> A great difference. The reason for this is, that the
> #include <ace/OS.h> somehow defines _REENTRANT, which
> triggers the boost library to include a mutex in
> sp_counted_base. I think, the order of the includes
> should not matter. Therefore, either '#include <ace/OS.h>'
> should not define _REENTRANT, or the boost headers
> should ignore it.
I agree this is annoying. The point is ace/OS.h has safety guards to
automatically #define _REENTRANT if you have forgotten to do it
yourself. Indeed, the library itself is compiled with -D_REENTRANT,
and this is captured into config-linux.h. If you happen to forget
#defining _REENTRANT (or using -pthreads), then you might end up with
link errors.
So, to recap, even though I agree that the order of #include should not
change your program behaviour, not defining _REENTRANT whenever you use
ACE will *not* work. And defining _REENTRANT will make both programs
print 36.
Another way of enforcing correct flags would be to check whether symbol
_REENTRANT is defined, and if it is not, the header could abort
compilation with an #error stating _REENTRANT *must* be defined.
I am not convinced this is better. What do you think?
Regards,
Thomas
More information about the Pkg-ace-devel
mailing list