9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] cast issue
       [not found] ` <CAOw7k5hJ4HRyGrLTC2wCssBrZEqVcmFe37eR3DQs5ciQ_xDOJA@mail.gmail.com>
@ 2012-02-28 18:02   ` Charles Forsyth
  0 siblings, 0 replies; only message in thread
From: Charles Forsyth @ 2012-02-28 18:02 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I never seem to get the right reply-to.

But, that gives me a chance to add that:
 to guarantee sign-extension, using (char) isn't good enough,
since it's not defined whether that's signed or unsigned. you need
(schar) [signed char]
as the cast. All Plan 9 compilers have char as signed.

---------- Forwarded message ----------
From: Charles Forsyth <charles.forsyth@gmail.com>
Date: 28 February 2012 17:53
Subject: Re: cast issue
To: erik quanstrom <quanstro@quanstro.net>


      if((uint)p[1] >= 256)
              print("x\n");
      if((int)p[1] < 0)
              print("y\n");

those two are unsigned. p[1] is uchar. i think that one's the same
under both unsigned-preserving
and value-preserving rules. it's hard to tell with gcc, because it tosses away
the code to test the impossible (which 6c and 8c could obviously do as well).
(char)p[1] produces a sign-extending move byte, though.

On 28 February 2012 13:44, erik quanstrom <quanstro@quanstro.net> wrote:
> however, the code generated is also curious.  the cast to int is
> ignored in the comparison.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-02-28 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <751d023752e74686a397bfd5fe76b9a7@chula.quanstro.net>
     [not found] ` <CAOw7k5hJ4HRyGrLTC2wCssBrZEqVcmFe37eR3DQs5ciQ_xDOJA@mail.gmail.com>
2012-02-28 18:02   ` [9fans] cast issue Charles Forsyth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).