public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Perry Smith <pedz@easesoftware.net>
To: gcc-help@gcc.gnu.org
Subject: integral type conversions
Date: Fri, 24 Mar 2006 03:00:00 -0000	[thread overview]
Message-ID: <9DD53BC1-A06B-499B-8BA0-E23D82476F1C@easesoftware.net> (raw)

I can't understand the C++ spec.  It seems more vague than the old K&R.

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?

e.g.

int i;

unsigned long l = i;

Is i sign extended from int to long and then converted to unsigned  
long or is it converted to unsigned int and then zero extended to  
unsigned long?

(assume that long is bigger in this case).  I'm actually going from a  
long to an unsigned long long but I assume the same algorithm is used.

I guess, to be safe, I could do:

unsigned long l = static_cast<unsigned int>(i);

Thank you,
Perry

             reply	other threads:[~2006-03-24  3:00 UTC|newest]

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

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=9DD53BC1-A06B-499B-8BA0-E23D82476F1C@easesoftware.net \
    --to=pedz@easesoftware.net \
    --cc=gcc-help@gcc.gnu.org \
    /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).