energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
795 stars 671 forks source link

sprintf() Bug on MSP430G2553 #249

Closed rei-vilo closed 11 years ago

rei-vilo commented 11 years ago

The second valued passed to sprintf (here, number2) isn't taken into account on MSP430G2553 while it is done correctly on LM4F120H5QR:

Results

sprintf(buffer, "%i.%i", number1, number2); gives

MSP430G2553
----
buffer  1234.0

LM4F120H5QR
----
buffer  1234.5678

Code

void setup()
{
  Serial.begin(9600);
  Serial.println("----");

  char buffer[16];
  uint32_t number1 = 1234;
  uint32_t number2 = 5678;

  sprintf(buffer, "%i.%i", number1, number2);
  Serial.print("buffer \t");
  Serial.println(buffer);

  Serial.end();
}

void loop()
{
}
astuder commented 11 years ago

As sprintf() is part of stdio.h / libc.a, I suspect this to be a msp430-gcc issue.

robertinant commented 11 years ago

sprintf seems to be broken in msp430 libc if either of the numbers is of type uint32_t. If both are declared as type uint16_t then it prints correctly. There is little I can do about this right now other than suggest the mentioned work-around.