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 > Codewarrior Embedded > Re: HCS12 Compi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 366 of 416
Post > Topic >>

Re: HCS12 Compiler warning

by "Gary Schnabl" <LivernoisYards@[EMAIL PROTECTED] > Dec 16, 2005 at 09:12 AM

"msolem" <msolem@[EMAIL PROTECTED]
> wrote in message 
news:1134687249.553014.197220@[EMAIL PROTECTED]
>I get this warning:
>
> C2705: Possible loss of data.
>
> when compiling this code:
>
>    char var = 8;
>    var = var / 2;
>
> If I change var from a char to a short, the warning disappears.
> I tried casting the '2' above to char, but that didn't help.
> Why am I gettng this warning when using a char?
>
> Mike


My $0.02 read:
While doing (var = var / 2;), the expression (var/2) is promoted to a 
default short or an int (both 2 bytes, I think) because the constant 2 is 
considered to be an int (or a short). A short or an int in the expression
- 
the 2 - causes the promotion to the larger entity. Then the assignment to
a 
char variable (var) demotes the short or int back into a char (one byte). 
Whenever that occurs, the compiler probably automatically generates the
2705 
warning. It's only a warning, so ignore it.

When you declared var as a short, the demotion to a char was not
performed. 
Therefore, no 2705 demotion warning.
 




 4 Posts in Topic:
HCS12 Compiler warning
"msolem" <ms  2005-12-15 14:54:09 
Re: HCS12 Compiler warning
"Gary Schnabl"   2005-12-16 09:12:15 
Re: HCS12 Compiler warning
"msolem" <ms  2005-12-16 08:53:49 
Re: HCS12 Compiler warning
"Gary Schnabl"   2005-12-16 14:58:32 

Post A Reply:
  Go here to Signup

AddThis Feed Button


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

Contact
tan12V112 Sat Oct 11 14:58:15 CDT 2008.