Joseph S. Myers wrote:
On Tue, 12 Jun 2012, Bin.Cheng wrote:
I noticed that GCC now can check format string of printf functions, so
I am wondering if it is possible to take advantage of this utility, by
making gcc detect whether printf prints floating point number and then
generate assembly directive in backend to pull in floating point
functions only if necessary.
Obviously this won't help if the program is using functions such as
vprintf to print things with variable format strings....
One method is to analyze the type of arguments when format strings are
varying. Though this method might fail when user trying to output a
"long long" type int with conversion specifier "%f", I think it's not
a big deal.
That method won't help for vprintf (unless you do something more
complicated and interprocedural) since then you have just a (probably
nonconstant) format strict and a (definitely nonconstant) va_list so don't
know the types of the arguments at all.
The original question does not belong to gcc development. It's an
embedded software tools issue.
The straightforward solution is to supply the (library internal)
...printf() function that ultimately handles any C-style output format
string. I mean a variant of this function that does not support floating
point output.
I used the word straightforward because embedded software development
usually implies more intricate issues with the run-time support library
(exception handling, dynamic memory, linker issues). The more serious
the memory restrictions in the embedded environment, the more critical
these issues become.
Let gcc development proceed as a great compiler technology!
Regards,
--
- Thierry Moreau
CONNOTECH Experts-conseils inc.
9130 Place de Montgolfier
Montreal, QC, Canada H2M 2A1
Tel. +1-514-385-5691