Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!nrl-cmf!ukma!rutgers!att!mtuxo!rolls!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c Subject: Re: Simple C Question (was: down) Summary: { 0 1 } != { -( 2**N ) ... ( 2**N )-1 } Message-ID: <128@mole-end.UUCP> Date: 21 Dec 88 07:14:35 GMT References: <192@broadway.UUCP> <6959@pyr.gatech.EDU> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 25 > I think I like one of the following two better: > chcnt += (c == '\n') ? 2 : 1; > chcnt += 1 + (c == '\n'); > > Any comments one which one of the ones we've seen is most efficient? I certainly hope that the economy or practicality of your program does not hinge on this! What's more important, I think, is that unless you have good reason for using tricks (e.g. you are writing a ``compiler'' that produces C) your second form ... + ( c == n ) works because [ 0 1 ] is the ordered set of things you want to AND COINCIDENTALLY [ 0 1 ] is the range of the C equality operators. Making your code depend on such a coincidence forces the reader to be mindful of the coincidence. If the code is human-written to be human-read, I believe that it's very poor practice. Besides, any respectable compiler should generate the same code for both, modulo the assembly language label names (if such there be). -- (This man's opinions are his own.) From mole-end Mark Terribile