Detecting mismatch of format string & parameters to vararg function

M

Mister B

I'm trying to detect a mismatch between the format string used by a
variable argument logging function and parameters passed in, e.g.:
raise_log ("Error val is %d %s", val);

I know that gcc -Wformat (implied by -Wall) can do this for standard
printf()-type functions; any suggestions for compiler options or other
tools for user functions?

M
 
K

Kenny McCormack

Your question is about gcc rather than about C, so you're likely
to get better answers from a gcc forum than you will here. FWIW, I
think the way you inform gcc that a user function is "printf-like"
or "scanf-like" is to use __attribute()__ markup. Check the "info."

You could have saved yourself a lot of trouble, as well as avoided
saying some incorrect and OT things, by just reducing all of the above
to the usual:

Off topic. Not portable. Cant discuss it here. Blah, blah, blah.

--
Useful clc-related links:

http://en.wikipedia.org/wiki/Aspergers
http://en.wikipedia.org/wiki/Clique
http://en.wikipedia.org/wiki/C_programming_language
 
L

lndresnick

     Your question is about gcc rather than about C, so you're likely
to get better answers from a gcc forum than you will here.  FWIW, I
think the way you inform gcc that a user function is "printf-like"
or "scanf-like" is to use __attribute()__ markup.  Check the "info."

Have a look here:

http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Function-Attributes.html#Function-Attributes

Search for the "format" one. Very nice for detecting mismatches at
compile time. I don't know of ways to do this, but there might be...

-David
 
E

Eric Sosman

Mister said:
As the OP, I did ask about other tools as well, so I think this is on
topic.

It's off-topic, but marginally so, because it's about
getting a particular compiler to do tricks that it alone
knows how to do, not about getting C to do tricks that a
wide assortment of different compilers can do. Since it
was only marginally off-topic I tried to give a helpful
response, complete with a warning that I might be wrong
and two pointers to better sources of information.

One further off-topic item, also intended to be
helpful: There's little to be gained by reading Kenny's
bait, and nothing to be gained by rising to it.
 
K

Kenny McCormack

Eric Sosman said:
One further off-topic item, also intended to be
helpful: There's little to be gained by reading Kenny's
bait, and nothing to be gained by rising to it.

Looks like Eric can be taken off the "might possibly have killfiled me"
list (at least for me - not sure about Han's list)

Note for readers new to the fray: When I say "killfile" above, I am
referring to what we in the trade call "real killfiling". There is
another kind of killfiling that is common on CLC - often referred to as
"fake killfiling". Many people (so I hear) engage in this later
activity, but very few in the former.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top