Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #17240

Re: Is this broken or wot?

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Is this broken or wot?
Date 2012-02-13 15:40 -0500
Organization A noiseless patient Spider
Message-ID <4F397543.90009@verizon.net> (permalink)
References <jhbm7t$9ng$1@speranza.aioe.org> <2krij75lrh0c035ornut2v8202qgut8p0e@4ax.com>

Show all headers | View raw


On 02/13/2012 03:14 PM, Barry Schwarz wrote:
> On Mon, 13 Feb 2012 18:53:49 +0000 (UTC), Robert Samelson
> <robs@invalid.com> wrote:
> 
>> unsigned x = 0;
>> if(x-- < 4)
>>                printf("foo\n");
>> else
>>                printf("bar\n");
>>
>> GCC for Data General Aviion 5000 (an 88000 machine) will convert this 
>> into:
>>
>>        unsigned x = 0;
>>        if(--x < 3) ....
>>
>> in the assembly.
>>
>> This seems broken if x == ~0.
> 
> As long as the code produces the correct response for any initial
> value of x, why would you think it broken?  For x initialized to 3, 2,
> or 1, it should print foo.  For all other others it should print bar.

No, for x initialized with 0 (as shown), the original C code should
print "foo\n", not "bar\n". What you've described corresponds to the
second sample of C code. That difference is why the rewrite would be
incorrect.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Is this broken or wot? Robert Samelson <robs@invalid.com> - 2012-02-13 18:53 +0000
  Re: Is this broken or wot? Willem <willem@toad.stack.nl> - 2012-02-13 19:19 +0000
  Re: Is this broken or wot? Barry Schwarz <schwarzb@dqel.com> - 2012-02-13 12:14 -0800
    Re: Is this broken or wot? James Kuyper <jameskuyper@verizon.net> - 2012-02-13 15:40 -0500
  Re: Is this broken or wot? Keith Thompson <kst-u@mib.org> - 2012-02-13 12:59 -0800
  Re: Is this broken or wot? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-13 14:30 -0800
    Re: Is this broken or wot? "Bl0ckeduser ." <bl0ckedusersoft@gmail.com> - 2012-02-13 18:13 -0800

csiph-web