Hi
I want to use signed long and unsigned long with snprintf. after some reading up I think I should use the ul and il tag.
However that does not give me the wanted result.
For instance:
void setup() {
// put your setup code here, to run once:
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
static unsigned long smallUnsigned =1;
static unsigned long bigUnsigned =100000;
static unsigned long smallSigned =-100000;
static unsigned long bigSigned =100000;
char printBuffer[100];
snprintf(printBuffer,sizeof(printBuffer),"smallUnsigned =%ul",smallUnsigned++);
Serial.println(printBuffer);
snprintf(printBuffer,sizeof(printBuffer),"bigUnsigned =%ul",bigUnsigned++);
Serial.println(printBuffer);
snprintf(printBuffer,sizeof(printBuffer),"smallSigned =%il",smallSigned++);
Serial.println(printBuffer);
snprintf(printBuffer,sizeof(printBuffer),"bigSigned =%il\n",bigSigned++);
Serial.println(printBuffer);
delay (1000);
}
creates following output (that is from the start)
smallUnsigned =1l
bigUnsigned =34464l
smallSigned =31072l
bigSigned =-31072lsmallUnsigned =2l
bigUnsigned =34465l
smallSigned =31073l
bigSigned =-31071lsmallUnsigned =3l
bigUnsigned =34466l
smallSigned =31074l
bigSigned =-31070lsmallUnsigned =4l
bigUnsigned =34467l
smallSigned =31075l
bigSigned =-31069lsmallUnsigned =5l
bigUnsigned =34468l
smallSigned =31076l
bigSigned =-31068l
The last character is always a l which indicates it is not interpreted. As such all the longs are interpreted as ints and return wrong values as soon as the MSB is used.
Do I use the wrong tag or is this a bug?
Best regards
Jantje