(with earlier/former releases it always worked fine)
edit: as expected, when using _fmt="%s" with sprintf(sval, _fmt, _val); instead of sval = FormatNum(_fmt, _val); it doesn't work neither!
Last edited by doc-helmut on 10 Aug 2012, 18:58, edited 1 time in total.
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
So it's probably more a BCC issue than a efw issue.
But as my whole output of almost all programs always uses the ANSI C compatible command printf() and almost never NumOut or TextOut I'll stay with the older version - it's better than nothing.
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
FormatNum should not work at all with strings so I am rather confused by this. Do I document anywhere that %s is a supported format specifier?
From your most recent post It sounds like you were simply getting lucky with a previously existing NXC bug that made it appear that %s was working when it was not actually working. Now that I have fixed that bug it looks even less like it works than it used to.
In any case, the fmtnum opcode definitely does not work with %s or a string argument as the value to replace in the format string. Since it is designed for formatting numbers I don't have any plans to change that.
That printf (and also print) is working both with numbers and with strings makes it ideal for variable output, and those format strings are supported by lots of other programming languages.
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
I just need to do a better job of documenting the differences between many of the NXC API functions which are designed to be similar to but not necessarily identical to C stdlib functions.
IMO, printf and a fmtstr operator for both numbers and strings would be fine.
BTW, my workaround I posted above works a little better with the latest BCC release. At least with printfxy there is a string output again with "%s", opposite to printf.
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !
Could you explain the need for FlattenVar in your workaround macro? It doesn't make any sense to me. Nothing sensible would happen if val is a numeric type and if val is a string there is no need to call FlattenVar since it is already a string.
It's a trick to outwit the compiler, respectively, the preprocessor. I tried it under different circumstances without, but simply, it doesn't work without. Instead, the compiler complains of any unknown constants (identified as identifiers) or wrong variable types using the macro both with numbers and also with strings and also with format strings containing additional text. My guess is that TextOut is expected to work with numbers but it doesn't work with numbers, or do you have another guess? Did you try the sample code without FlattenVar with better results?
regards, HaWeakaFord"A Kingdom of Heaven if NXC had recursions" Prefect ±≠≈αγδελπφωΔΦΣΩ∫√∈∉¬⊂⊄∩∪∅∞ NXC CHESS for NXT: url= http://www.mindstormsforum.de/viewtopic.php?f=70&t=6790
wishful for NXC: easy + trouble-free network & I/O remote control for rs485, Xbee, and BT !