From: Daniel M. <sd...@bl...> - 2013-02-18 11:43:49
|
Dear sdcc community, I am encountering a problem that is somehow connected to the cast between float and int, and it is unclear to me whether I am using sdcc wrong or whether there might be a bug somewhere. Please find below two pieces of code, the first one works as expected, the value of debug is 6116. The second does not work, I expect the value to be 6116, but I see a different number. It is not clear to me whether this is always the same number and what influences its value. I compile for a PIC16F1938, using sdcc from svn (rev8435), configured with --enable-new-pics (since pic16f1938 uses the "enhanced core") against gputils r932. $ sdcc -v SDCC : mcs51/gbz80/z80/z180/r2k/r3ka/ds390/pic16/pic14/TININative/ds400/hc08/s08 3.2.1 #8435 (Feb 17 2013) (Linux) I compile using $ sdcc -I/usr/local/share/sdcc/non-free/include/ -L/usr/local/share/^Ccc/non-free/lib/pic14/ -L/usr/local/share/^Ccc/lib/pic14 -mpic14 -p16f1938 problem.c When comparing the asm outputs I see that the first example does not call ___fs2uint, why does it not need to do this to cast the value of x? What else can I do to narrow the problem down? Is there a debugger in which I can run these programs on my computer and inspect the values after each step? Currently I use a board with connected LED displays to inspect the value of debug (program attached). Thank you for any help. //Daniel $ cat problem_works.c #define __16f1938 #include <float.h> #include "pic14/pic16f1938.h" static __code int __at(_CONFIG1) __CONFIG1 = _WDTE_OFF; unsigned int debug = 1234; void main(void) { float x = 6116.0; debug = x; //debug is 6116. } $ cat problem.c #define __16f1938 #include <float.h> #include "pic14/pic16f1938.h" /* Setup chip configuration */ static __code int __at(_CONFIG1) __CONFIG1 = _WDTE_OFF; unsigned int debug = 1234; float julianday = 6116.0; void main(void) { float x = 6116.0; debug = julianday; // expect 6116, obtain a vastly different (arbitrary?) number } |