Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Set the result of void function Date: Thu, 28 Sep 2017 09:25:25 -0700 Organization: None to speak of Lines: 38 Message-ID: References: <001b7bdd-f28a-4747-80da-81404481b320@googlegroups.com> <74b5ddce-96ec-48aa-a16c-a5a4207c17fe@googlegroups.com> <9546ff45-2666-4f32-8905-8d4baba8a74d@googlegroups.com> <877ewm1ook.fsf@bsb.me.uk> <65ac971c-10a1-41b1-876d-cdded04ea432@googlegroups.com> <6308c8a5-6a1e-4667-bac4-1cdaf18e7e55@googlegroups.com> <4c1bbda7-bee7-4dac-b9a1-7e2bd2d3486b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="f02d66d70d400004528cf8384483c39b"; logging-data="2037"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180Jew7xdOtis0RoT/o0dcG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:PJXPvEx8IleSzbOdx1a0thrKZsM= sha1:QAY+ANh2cjTVhyR+eqfOPbCPjFc= Xref: csiph.com comp.lang.c:120454 Malcolm McLean writes: [...] > Consider this > > /* > DNA base pairing partner > */ > char partner(char base) > { > switch(base) > { > case 'A' : return 'T'; > case 'C' : return 'G'; > case 'G': return 'C': > case 'T': return 'A': > default: assert(0); > } > } > > The function cannot legitimately be called with anything other > than one of the four DNA bases. But it isn't clear what it should > do if assertions are turned off. Returning garbage is probably > a reasonable answer. If we return 0 people might start relying > on the behaviour and mis-use the function as an "isDNABase(). I might consider adding `return '?';` after the assert, so that when NDEBUG is defined errors show consistent symptoms. Seeing '?' in the output is a clue that soomething is wrong. On the other hand, leaving off the return means that a sufficiently clever compiler might be able to diagnose some such errors at compile time. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"