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


Groups > comp.lang.c > #17234 > unrolled thread

Is this broken or wot?

Started byRobert Samelson <robs@invalid.com>
First post2012-02-13 18:53 +0000
Last post2012-02-13 18:13 -0800
Articles 7 — 7 participants

Back to article view | Back to comp.lang.c


Contents

  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

#17234 — Is this broken or wot?

FromRobert Samelson <robs@invalid.com>
Date2012-02-13 18:53 +0000
SubjectIs this broken or wot?
Message-ID<jhbm7t$9ng$1@speranza.aioe.org>
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.

[toc] | [next] | [standalone]


#17237

FromWillem <willem@toad.stack.nl>
Date2012-02-13 19:19 +0000
Message-ID<slrnjjioiv.2g8t.willem@toad.stack.nl>
In reply to#17234
Robert Samelson 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) ....

That doesn't look like assembly to me.
I assume this is your 'decompiling' of the actual assembly instructions.
It means that there either is a fault in the compiler's compilation, or
in your decompilation.  Without information on what the actual assembly
instructions are, it's hard to say which it is.

) in the assembly.
)
) This seems broken if x == ~0.

You should test what the actual output from the code is, to see if it
does what it's supposed to.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

[toc] | [prev] | [next] | [standalone]


#17239

FromBarry Schwarz <schwarzb@dqel.com>
Date2012-02-13 12:14 -0800
Message-ID<2krij75lrh0c035ornut2v8202qgut8p0e@4ax.com>
In reply to#17234
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.
Do you have results that show otherwise?

-- 
Remove del for email

[toc] | [prev] | [next] | [standalone]


#17240

FromJames Kuyper <jameskuyper@verizon.net>
Date2012-02-13 15:40 -0500
Message-ID<4F397543.90009@verizon.net>
In reply to#17239
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.

[toc] | [prev] | [next] | [standalone]


#17243

FromKeith Thompson <kst-u@mib.org>
Date2012-02-13 12:59 -0800
Message-ID<lnsjieih4v.fsf@nuthaus.mib.org>
In reply to#17234
Robert Samelson <robs@invalid.com> writes:
> 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.

It's broken if and only if the program produces incorrect output.  C
code specifies behavior, not machine code.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#17257

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2012-02-13 14:30 -0800
Message-ID<56a94565-cc9c-4e20-80a2-ae67be7650d6@18g2000yqe.googlegroups.com>
In reply to#17234
On Feb 13, 6:53 pm, Robert Samelson <r...@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.
>
Yes, it will fail, because of wrap round. If it prints "bar" than this
is a compiler bug.

[toc] | [prev] | [next] | [standalone]


#17276

From"Bl0ckeduser ." <bl0ckedusersoft@gmail.com>
Date2012-02-13 18:13 -0800
Message-ID<0362a3b2-ff48-4d93-9055-21e5a66299e9@gr6g2000vbb.googlegroups.com>
In reply to#17257
I was convinced once that gcc generated wrong code
because my program ran differently on two machines.

But further inspection revealed that I was using the %
operator on a zero operand.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web