This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: return-value policy question
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Nathan Myers <ncm-nospam at cantrip dot org>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: 29 Apr 2003 13:15:57 +0200
- Subject: Re: return-value policy question
- Organization: Integrable Solutions
- References: <20030429053012.GG32140@tofu.dreamhost.com>
Nathan Myers <ncm-nospam at cantrip dot org> writes:
| In much of the library implementation I find code like that in
| streambuf::sputc :
|
| int_type __ret;
| if (_M_out_cur < _M_out_end)
| {
| *_M_out_cur = __c;
| _M_move_out_cur(1);
| __ret = traits_type::to_int_type(__c);
| }
| else
| __ret = this->overflow(traits_type::to_int_type(__c));
| return __ret;
|
| instead of the simpler and more elegant
Frankly, I can't find in what the second version is simpler and more
elegant. The former compute the value to return in either branches,
and in a single return-statement returns the computed value.
Having -- recently -- to monitor return-statements in the compiler I
found it
* astonishingly helfpul that functions that span may pages have a
single return statement and very easy to monitor;
* functions that had many return-statements were the ones that
provided many opportunities for having the auditing worng;
* the functions with a single return-statement are no harder to
read (actually it was the functions with many return-statements
that were harder to read).
[...]
| or the even simpler and more traditional
|
| return (_M_out_cur < _M_out_end) ?
| traits_type::to_int_type(*_M_out_cur++ = __c) :
I find such an assignment a good candiate for obfuscations, not for
clarifications.
-- Gaby