You are 100% correct. You nailed it. Stroustrup p. 263: "If both operands
have arithmetic type, the right operand is converted to the type of the left
preparatory to the assignment."

That explains why it fails, but not why it works Opt(0). I am going to
*guess* that Opt(0) it compiles as though I had coded testWord =
static_cast<unsigned int>(valueToTest >> 32) while with Opt(2) it compiles
as though I had coded testWord = static_cast<unsigned int>(valueToTest) >>
32;

In your earlier post you suggested "wasting" another long long. Yes, that's
an approach. Actually I am finished with valueToTest and can just do things
in two steps without "wasting" a variable:

valueToTest >>= 32;
testWord = valueToTest;

I am busy with other things perhaps until sometime this week but the first
thing I am going to try is simply using parentheses to attempt to "force"
the "Opt(0)" interpretation:

testWord = (valueToTest >> 32);

If that fails I will move on to more elaborate approaches. The "two
statement" approach will either work or else it is a very clear bug and I
will re-group. Will probably try the union approach at that point.

Thanks!

Charles

-----Original Message-----
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
Behalf Of Bernd Oppolzer
Sent: Sunday, July 21, 2013 9:44 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: Looking for help with an obscure C integer problem

BTW:

I think I remember from an old book on C programming:

"if the target of an assignment is int, all operands on the right side are
converted to int - if the target of an assignment is long, all operands on
the right side are converted to long"

If I remember correctly, this would perfectly explain the behaviour you see
(of course, it makes more sense for data types being shorter than the type
of the assignment target, but if it's done as written above, you have it for
longer types, too).

Kind regards

Bernd




Am 21.07.2013 18:32, schrieb Bernd Oppolzer:
> Sorry for jumping late into this thread.
>
> Why not spend another variable of type long long to do the shift there?
>
> like
>
> unsigned long long valueToTest;
> unsigned int testWord;
> unsigned long long x;
>
> x = valueToTest >> 32;   /* here */
> testWord = (int) x;

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to