cancel
Showing results for 
Search instead for 
Did you mean: 

COSMIC Type Cast Problem

laffer
Associate
Posted on December 22, 2009 at 12:12

COSMIC Type Cast Problem

3 REPLIES 3
laffer
Associate
Posted on May 17, 2011 at 15:06

We have 2 issues during using COSMIC Compiler 4.3.1 16k Limit version and STVD 4.1.3, R-Link.

First, we don’t have functional value through using Local Variable, when we use as above it shows different value on long_var.

void main(void)

{

long long_var = 0;

float float_var = 0;

long_var = 533485489;

float_var = (float)long_var;

while (1)

{

}

}

http://www.insem.co.kr/100201/1_local.gif

Second, Type Casting problem.

long long_var = 533485489;

float float_var = 0;

void main(void)

{

float_var = (float)long_var;

while (1)

{

}

}

It showed wrong value on float_var as it was inserted Type Casting after we declared global variable,

http://www.insem.co.kr/100201/2_cast_fail.gif

however, it goes properly in main function as follows.

long long_var;

float float_var = 0;

void main(void)

{

long_var = 533485489;

float_var = (float)long_var;

while (1)

{

}

}

http://www.insem.co.kr/100201/3_cast_success.gif

We think it has a problem, isn’t it?

krzysztof239955_st
Associate II
Posted on May 17, 2011 at 15:06

Hi,

The setting Display Item from Decimal on Standard in debuger solved the problem.

Regards

Kris.

luca239955_st
Associate III
Posted on May 17, 2011 at 15:06

also, when you work with local variables that are not actually used for anything, the compiler sometimes optimize them out: use globals or, at least, declare the locals volatile, to avoid this.