public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: John Love-Jensen <eljay@adobe.com>
To: Perry Smith <pedz@easesoftware.net>, MSX to GCC <gcc-help@gcc.gnu.org>
Subject: Re: integral type conversions
Date: Fri, 24 Mar 2006 12:54:00 -0000	[thread overview]
Message-ID: <C0494813.C637%eljay@adobe.com> (raw)
In-Reply-To: <9DD53BC1-A06B-499B-8BA0-E23D82476F1C@easesoftware.net>

Hi Perry,

> If the source is a signed integral type and the destination is an
> unsigned integral type that is larger, are the additional bits done
> via sign extension or zero extension?

On 2's complement machines (the only sort I've ever used), the additional
bits are done via sign extension.

This behavior should be identical to the behavior in C.

Side note: I use the Java convention of converting a char to an int:

char c = '\xAA';
int i;
i = c & 0xFF;

Works the reliably on plain-char-is-signed and plain-char-is-unsigned
machines.  Presuming the architecture is 8-bit-bytes (such as all my
platforms are).  And I'm not sure if there's caveats for 1's complement
machines to worry about.

Sincerely,
--Eljay

      reply	other threads:[~2006-03-24 12:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-24  3:00 Perry Smith
2006-03-24 12:54 ` John Love-Jensen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=C0494813.C637%eljay@adobe.com \
    --to=eljay@adobe.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=pedz@easesoftware.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).