Re: NXC: format string "%s" doesn't work with printf
Posted: 09 Aug 2012, 16:20
Just to demonstrate what was going wrong with FormatNum before it was fixed, here's the underlying NBC code that used to be generated:
As you can see here, the __strbufmain value, which was the format specifier, was being being incorrectly overwritten by the string. The compiler was failing to complain about this. Then the fmtnum opcode was using "line 1 printf" as the format string and the numeric value (__constVal1) was ignored. This bug has been fixed. The new code looks like this:
As you can see, it no longer incorrectly overwrites the format string.
I am investigating an enhancement to the fmtnum opcode which would allow it to take a string for its third argument.
John Hansen
Code: Select all
strcat __strbufmain, "%s"
strcat __strbufmain, "line 1 printf"
fmtnum __strretvalmain, __strbufmain, __constVal1
strcat __strbufmain, __strretvalmain
Code: Select all
strcat __strbufmain, "%s"
mov __ArrHelper__main_244_0, __strbufmain
strcat __strbufmain, "line 1 printf"
fmtnum __strretvalmain, __ArrHelper__main_244_0, __constVal1
strcat __strbufmain, __strretvalmain
I am investigating an enhancement to the fmtnum opcode which would allow it to take a string for its third argument.
John Hansen