Skip to main content
Visitor II
December 22, 2009
Question

COSMIC Type Cast Problem

  • December 22, 2009
  • 3 replies
  • 901 views
Posted on December 22, 2009 at 12:12

COSMIC Type Cast Problem

    This topic has been closed for replies.

    3 replies

    lafferAuthor
    Visitor II
    May 17, 2011
    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?

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 15:06

    Hi,

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

    Regards

    Kris.

    Visitor II
    May 17, 2011
    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.