This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]