libstdc++/16612, empty basic_strings can't live in shared memory

Carlo Wood carlo@alinoe.com
Wed Aug 4 19:19:00 GMT 2004


On Wed, Aug 04, 2004 at 09:59:14AM -0700, Nathan Myers wrote:
>   union { _CharT* _M_data; _CharT _M_nul };
> 
> and define
> 
>   inline _CharT* c_str()
>     { return (this->data() ? this->data() : &this->_M_nul); }
> 
>   inline _CharT& operator[](size_t i)
>     { return this->c_str()[i]; }
> 
> One can hope that the optimizer might hoist the test out of loops.
> (Fat chance.)  

This looks good :).  Dirty, but smart.

Just out curiosity - wouldn't it be better to write:

   inline _CharT* c_str()
     { return (this->_M_data ? this->_M_data : &this->_M_nul); }

?

I mean - why add an extra function call there for the case -O0 ?

-- 
Carlo Wood <carlo@alinoe.com>



More information about the Libstdc++ mailing list