Minor issue/discussion: Behaviour of printf-family depends on optimization-flags [I.e. "(null)" - replacement]
Markus Eisenmann
meisenmann.lba@fh-salzburg.ac.at
Fri Dec 18 13:54:00 GMT 2015
Hi!
I've found a minor issue in the (inner) vprinter-implementation and would like to "discuss", whether this is really wanted ...
The source files newlib/libc/stdio/vfprintf.c, and similar in newlib/libc/stdio/vfwprintf.c
are containing a code, which depends on compiler optimization-flags, I.e.:
#ifndef __OPTIMIZE_SIZE__
/* Behavior is undefined if the user passed a
NULL string when precision is not 0.
However, if we are not optimizing for size,
we might as well mirror glibc behavior. */
if (cp == NULL) {
cp = "(null)";
size = ((unsigned) prec > 6U) ? 6 : prec;
}
else
#endif /* __OPTIMIZE_SIZE__ */
In my opinion, a functional behaviour (as time-invariant black-box) should not differ,
if the compilation is done with different optimizer-flags (expect -O3, what
sometimes causes problems/side-effects, but this is another story).
Personally, I suggest to drop the #ifndef / #endif lines, with adopting the comment slightly.
Okay, the behaviour on passing a NULL string isn't defined, but in glibc there's pre-proc exclude
like this. Furthermore, the result of a function (expect stack-usage, timing/performance) should
be always as expected (or documented), regardless whether it's compiled without or with
size/speed optimization, if no (other) configuration has changed .
Greetings from Salzburg,
Markus
More information about the Newlib
mailing list