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

Problem with sprintf of float

Hi,
I have a strange problem with sprintf() function.
Sometimes when i declare new variable in my project (for example an U8) and I attempt to printf a previously declared float variable in a string a problem occurred.
My string contain lots of strange character but before new declaration no problem was occurred.

Variable is printed on this way:
printf((S8 *)(serial_string),%.1f\t",pos5v_measure);

my declaration:
U8 serial_string[0x400];
float pos5v_measure;

my settings:
pos5v_measure = config_buffer[n] (U8 var)

Otherwise if i use:
printf((S8 *)(serial_string),%d.%d\t",pos5v_measure/10,pos5v_measure%10);
problem is solved,it means that pos5v_measure contains the correct value.

But why??
Have any idea???

PS:My compiler is realview and my project is been converted from CARM to realview

Thank you, Manuel

Parents
  • "Sometimes when i declare new variable in my project (for example an U8)"

    U8 serial_string[0x400];
    Hold on a moment: that's not just "an U8" - that's a whopping great array of U8s - a whole 1K of them!! :-0

    Have you checked carefully for memory overflow, stack overflow, etc?

Reply
  • "Sometimes when i declare new variable in my project (for example an U8)"

    U8 serial_string[0x400];
    Hold on a moment: that's not just "an U8" - that's a whopping great array of U8s - a whole 1K of them!! :-0

    Have you checked carefully for memory overflow, stack overflow, etc?

Children
  • Hi,
    I use sprintf() function, in previously message i erase 's' character from sprintf(), sorry.
    I use sprintf()!!

    PS: memory stack overflow is not present, i debug project and increase all stack memory and after if it is a stack problem why if i sprintf() a float variable as %d system work correctly??

    PPS: i note in map file created from realview that the new define variable (that is U8 variable) use more than 1 byte but for example 3 byte!!Strange or normal??? It is the memory alignment!!But very strange that is the new declared variable that use more than 1 byte!!

    Hi, Thanks

  • Can we get a complete source example that can be compiled?