float corrupted when passed into variable argument list
Posted: Thu Jan 05, 2012 8:01 pm
I'm not sure if this problem is related to the byte alignment of chibios or just a general GCC related problem.. but here goes!
I'm trying to printf() some floats. From the main thread, everything works as expected. However, if I try to print a float from within another thread, it gets corrupted. For example, here's a little function which gets a pointer to the variable argument list as an offset from the first argument, then prints out the bytes:
Then I call it in a few threads (main thread is first row)
With output:
This behaviour is consistent for other values. E.g 0.087:
So it looks as if the first two bytes get corrupted somehow. I replaced my ld script with the latest one to make sure I haven't messed something up there, but the same thing happened. Anyone got an ideas what might be causing this?
I'm trying to printf() some floats. From the main thread, everything works as expected. However, if I try to print a float from within another thread, it gets corrupted. For example, here's a little function which gets a pointer to the variable argument list as an offset from the first argument, then prints out the bytes:
Code: Select all
void float_test(int ignored, ...) {
int *varg = (int *) (char *) (&ignored);
varg++;
unsigned char *adr = (unsigned char *)(varg++);
for(int i=0; i < 8; i++)
cPrintf("%x ", adr[i]);
cPrint("\r\n");
}
Then I call it in a few threads (main thread is first row)
Code: Select all
float_test(10, 0.045f);With output:
Code: Select all
38 28 0 20 0 0 0 80
0 28 0 20 0 0 0 80
30 13 0 20 0 0 0 80This behaviour is consistent for other values. E.g 0.087:
Code: Select all
38 28 0 20 0 0 0 c0
0 28 0 20 0 0 0 c0
30 13 0 20 0 0 0 c0So it looks as if the first two bytes get corrupted somehow. I replaced my ld script with the latest one to make sure I haven't messed something up there, but the same thing happened. Anyone got an ideas what might be causing this?