This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

double trouble?

Hi all.

using uVision 4, keil compiler.

I'm trying to create a very simple function that takes an argument list, but it seems like when i use parameters of type double, it doesn't work right. I started fiddling around with the double datatype, and maybe i'm doing something wrong, but ...


// double trouble
double d = 1234.1234;
double* dp = &d;
double e = *dp;
// e has gibberish, d is fine

// float is ok
float f = 1234.1234;
float* fp = &d;
float g = *fp;
// g is fine, f is fine

// in fact ...
float f = 1234.1234;
float* fp = &d;
double g = *fp;
// g has gibberish, f is fine

// also ...
float f = 1234.1234;
double d = (double)f;
// d has gibberish(!)

// wha...
double d = 1234.1234;
double e = d;
// both d and e have gibberish.

// contrast to
float d = 1234.1234;
float e = d;
// both d and e are fine

// adding a pointer.. cures it?
double d = 1234.1234;
double* dp = &d;
double e = d;
// e has gibberish, d is fine.

// more pointers...
double d = 1234.1234;
double* dp = &d;
double e = d;
double* ep = &e;
// both d and e are fine.

can someone explain what's going on???

  • well, it seems it is IDE related. doing the following works as expected...

      char temp[100];
      double a = 1234.1234;
      double b = a;           // both a and b are gibberish but...
      sprintf(temp,"%lf", a); // temp now is "1234.1234"
    
    

  • it seems it is IDE related

    It appears that the uVision debugger doesn't interpret variable values correctly in some cases. It could be inaccurate debugging information provided by the compiler, or the debugger interprets that information incorrectly. You can try and reduce optimization level and hope that debugging gets easier.