return-value policy question

Phil Edwards phil@jaj.com
Tue Apr 29 18:07:00 GMT 2003


On Mon, Apr 28, 2003 at 10:30:12PM -0700, Nathan Myers wrote:
> In much of the library implementation I find code like that in
> streambuf::sputc :
> 
>       int_type __ret;
[assign in multiple branches]
>       return __ret;
> 
> instead of the simpler and more elegant
> 
>       if (_M_out_cur < _M_out_end)
>         {
>           *_M_out_cur = __c;
>           _M_move_out_cur(1);
>           return traits_type::to_int_type(__c);
>         }
>       return this->overflow(traits_type::to_int_type(__c));

I find the former /much/ easier to debug, but that's personal preference.
Also, the optimizations being implemented and planned for SSA form tend
to make this sort of thing a moot point.  So, *shrug*, whichever.


> or the even simpler and more traditional
> 
>       return (_M_out_cur < _M_out_end) ?
>         traits_type::to_int_type(*_M_out_cur++ = __c) :
>         this->overflow(traits_type::to_int_type(__c));

Normally I'm not a style bigot, but Sweet Lord, that's hideously ugly.


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



More information about the Libstdc++ mailing list