From: Eljay Love-Jensen <eljay@adobe.com>
To: "Sivaprasad.pv" <sivaprasad.pv@redpinesignals.com>,
GCC-help <gcc-help@gcc.gnu.org>
Subject: Re: regarding type promotion
Date: Tue, 19 Aug 2008 15:35:00 -0000 [thread overview]
Message-ID: <C4D03375.7E82%eljay@adobe.com> (raw)
In-Reply-To: <48AA5377.9080001@redpinesignals.com>
Hi Siva,
> If we consider following sample C language code :
>
> long long int k=0x123;
> int p=1;
> k = k + p << 33;
>
> Here the value in variable 'p' is shifted by 33 and then the result
> (only 32 bit result)was promoted to 64 bit.
Yes, that's correct.
((k) = ((k) + ((p) << (33))));
Using L to mark long long, and I to mark int, and @ to mark promotion:
L(L(k) = L(L(k) + L@(I(I(p) << I(33)))));
Also note that where int is 32-bit, doing a i << 33 is undefined behavior.
It could shift to zero. It could leave the number as-is. It could shift by
one. It could... DESTROY THE UNIVERSE. So be careful with that.
(If shifting a 32-bit int by 33 with GCC does destroy the universe, please
file a bug <http://gcc.gnu.org/bugs.html>.)
> Is it an expected behavior?
Yes.
> Is there any way to specify in gcc to perform implicit type promotion
> first and then perform operation on it (without explicit type casting).
Yes.
long long k=0x123; // <-- implicit promotion 0x123 --> 0x123LL
long long p=1; // <-- implicit promotion 1 --> 1LL
k = k + p << 33;
HTH,
--Eljay
next prev parent reply other threads:[~2008-08-19 13:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-19 8:38 Sivaprasad.pv
2008-08-19 13:24 ` Andrew Haley
2008-08-19 15:35 ` Eljay Love-Jensen [this message]
2008-08-19 16:33 ` Bob Plantz
2008-08-19 16:34 ` Richard Harvey Chapman
2008-08-19 17:02 ` Ian Lance Taylor
2008-08-19 22:07 ` Richard Harvey Chapman
2008-08-20 2:28 ` Ian Lance Taylor
2008-08-19 22:36 ` Richard Harvey Chapman
2008-08-19 16:45 ` Richard Harvey Chapman
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=C4D03375.7E82%eljay@adobe.com \
--to=eljay@adobe.com \
--cc=gcc-help@gcc.gnu.org \
--cc=sivaprasad.pv@redpinesignals.com \
/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).