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

[Cortex-A8] beginner lost with simple floats

Note: This was originally posted on 25th June 2012 at http://forums.arm.com

can anyone please explain to a beginner why a simple program (below) apparently corrupts the Locals (as seen in IDE, image below).
It doesn't seem to happen for integers, though.
Sure I'm doing something wrong, but what is it, and how to fix?
It's modified "startup_Cortex-A8", going emulator "startup-Cortex-A8-RTSM-example.launch" (otherwise all fresh installation)

int main(void)
{
  float A;
  float B;
  float C;
  float D;
  A = 1.2f;
  B = 2.3f;
  C = 3.4f;
  D = B + C;
  return 0;
}

Parents
  • Note: This was originally posted on 26th June 2012 at http://forums.arm.com

    What compiler and optimization level are you using?

    The compiler is only required to make the sure the function behaves according to the standard -- this does not include debugging.  Since your function returns 0, the variables A, B, C and D don't really affect anything and the compiler can eliminate them partially or completely if it wants.  In fact, if you look in the Location column of the float case, you can see that B and C have both been put in the same register.

    You can probably convince the compiler to keep the variables by taking their addresses and passing them to another function, e.g.

      printf("&A=%p, &B=%p, &C=%p, &D=%p\n", &A, &B, &C, &D);
Reply
  • Note: This was originally posted on 26th June 2012 at http://forums.arm.com

    What compiler and optimization level are you using?

    The compiler is only required to make the sure the function behaves according to the standard -- this does not include debugging.  Since your function returns 0, the variables A, B, C and D don't really affect anything and the compiler can eliminate them partially or completely if it wants.  In fact, if you look in the Location column of the float case, you can see that B and C have both been put in the same register.

    You can probably convince the compiler to keep the variables by taking their addresses and passing them to another function, e.g.

      printf("&A=%p, &B=%p, &C=%p, &D=%p\n", &A, &B, &C, &D);
Children
No data