Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: GCC hasn't even gotten around to sequencing argument evaluation Date: Sat, 09 Apr 2022 09:38:18 -0700 Organization: A noiseless patient Spider Lines: 51 Message-ID: <86ee269pqd.fsf@linuxsc.com> References: <2eba800a-d920-4f60-abed-4c687a971a67n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="b8e2dcfc2935dcfe9151ae6ef6f0e059"; logging-data="10326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+GUx0fu1J+saj6iVqcBunhr2AGNq68R0I=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:7A2vMGqJVYspQ/f5covIw82j8yk= sha1:w5Grx9vSWYf1HX4EiIqmmmpAyAI= Xref: csiph.com comp.lang.c++:83548 Tiib writes: > On Thursday, 7 April 2022 at 00:34:23 UTC+3, Sams Lara wrote: > >> On 06/04/2022 19:50, James Kuyper wrote: >> >>> If you think that the first ++i must be evaluated before the >>> second ++i, just because it's "defined first", then you've made >>> the mistake that people have been accusing you of. >> >> Perhaps the accusation may not be justified because there are times >> you want to know that the order will be preserved. For example, if >> you have a function like so: >> >> string BinaryString(int Number) >> { >> if (Number == 0) >> { >> return "0"; >> } > > Note that else after if that returns or throws is superfluous: > >> else >> if (Number == 1) >> { >> return "1"; >> } > > Here too excessive else: > >> else >> { >> return (BinaryString(Number / 2) + BinaryString(Number % 2)); >> } > > Unreachable return. Would be obvious without redundant elses: Better to get rid of all those pesky if() statements and just use one return (disclaimer: not compiled): string BinaryString( const int N ){ return N == 0 ? "0" : N == 1 ? "1" : BinaryString( N *1u /2 ) + BinaryString( N *1u %2 ); } (Note: the 1u factors in the last line are there to avoid a nasty bug when N is negative.)