Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Compilers LCC > Re: Short Integ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 3 Topic 985 of 1066
Post > Topic >>

Re: Short Integer Constants in LCC-WIN32?

by "Antoine Leca" <root@[EMAIL PROTECTED] > Oct 8, 2007 at 11:11 AM

En news:46fa8918$0$27384$ba4acef3@[EMAIL PROTECTED]
 jacob navia va escriure:
> John Willett wrote:
>> Is there a way to explicitly specify a short-integer constant in
>> LCC-WIN32? I'm revising old 16-bit code written for Windows 3.1, and
>> I'm encountering a lot of expressions like "filerec.timelow &
>> 0x7C00u".  "Filerec.timelow" was originally declared as "int" but
>> must now be changed to "short" because the structure is read from a
>> pre-existing binary file.  Obviously, it would be nice if the
>> constant, "0x7C00u", were also a "short" (although it appears to run
>> correctly as is), but I don't see any suffix (like "us", for
>> example) in the do***entation.
>>
>>
> No, there isn't any way to do that, maybe because the
> standard specifies that AND operations between two
> shorts are promoted to ints, then the results are
> converted to whatever needs to be done.

That is not entirelly correct.
In the 32-bit world, Jacob is correct, both terms are converted to signed
int. However, in the 16-bit world, in an operation between a signed short
variable and a unsigned int constant, arguments are promoted to the
unsigned
type; this means two im****tant variations: the variable is converted from
signed to unsigned (should not be a problem), and the result is unsigned,
not signed (THIS, in turn, could affect the rest of the computations.)

Of course, if "Filerec.timelow" were originally declared as "unsigned
int",
then transformed to "unsigned short", it would probably have been better
and
clearer in the first place...


> Mostly this doesn't affect the results.

This was the position of the C committee, which chose these rules to
achieve
the principle of lesser surprise (particularly when ****ting form 16-bit to
32-bit.)


Antoine
 




 3 Posts in Topic:
Short Integer Constants in LCC-WIN32?
"John Willett"   2007-09-26 11:40:27 
Re: Short Integer Constants in LCC-WIN32?
jacob navia <jacob@[EM  2007-09-26 18:29:20 
Re: Short Integer Constants in LCC-WIN32?
"Antoine Leca"   2007-10-08 11:11:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 7:09:59 CDT 2008.