0

I wanted to define a macro like -

#define  log(lognumber,...)  logreport(lognumber,__VA_ARGS__) 

I wanted to check the exception case for __VA_ARGS__ those arguments user can pass when that user calls log() .please provide me exception case for __VA_ARGS__ .


[update from comment:]

I mean I wanted to write logreport in such a way that it should print the specific number to the error that I had defined already.

Taking an example like if I am passing

log(NOTE,"%s",str) 

then in that case it prints the specific ids which I have assigned in another file like this msgid %s, msdstr %s (10223), but user uses

log(NOTE,"DIRECT STRING") 

it does take the [???] for that string. So how would I check that if user is passing an argument this way

log(NOTE,"%s",str) 

or

log(NOTE,"direct string") 

this way in logreport function?

alk
  • 69,737
  • 10
  • 105
  • 255
  • 2
    What do you mean by "exception case"? What exactly are you trying to achieve / protect against? – cnicutar May 14 '15 at 12:20
  • Just write code in the logreport function to do the checking using the standard `va_start`, `va_arg` and `va_end` macros to operate on the variable args. At least that's an answer to what I think you are asking. But your question is not very clear: "exception case for `__VA_ARGS__`" is not a term that makes sense without explaining what that means. – kaylum May 14 '15 at 12:22
  • If I read this correctly (and I'm not sure I do), you may be interested in http://stackoverflow.com/questions/2124339/c-preprocessor-va-args-number-of-arguments – Wintermute May 14 '15 at 12:26
  • Like the others, not sure what you're after exactly. If you want to check that printing formats correspond to arguments, you cannot do that in the function or in the macro. But some compilers might allow you to issue compile-time warnings, for example, gcc has the [`format` attribute](http://stackoverflow.com/questions/996786/how-to-use-the-gcc-attribute-format), which you could specify on the `logreport` function. – M Oehm May 14 '15 at 12:28
  • I mean i wanted to write logreport in such a way that It should print the specific number to the error that i had defined already ,Taking an example like if i am passing log(NOTE,"%s",str) then in that case It prints the specific ids which i have assigned in another file like this msgid %s ,msdstr %s (10223) ,but user uses log(NOTE,"DIRECT STRING") It does take the for that string ,So how would i check that if user is passing an argument this way log(NOTE,"%s",str) or log(NOTE,"direct string") this way in logreport function – user2230832 May 14 '15 at 13:37

1 Answers1

0

So how would I check that if user is passing an argument

As it stands the only way is to parse the second argument for the occurency of some conversion specifier like "%s".

alk
  • 69,737
  • 10
  • 105
  • 255