<div dir="ltr">Hey all,<br><br>I have the exact same problem  as this old message on the gcc-help mailing list.<br><br><a href="http://gcc.gnu.org/ml/gcc-help/2010-03/msg00114.html">http://gcc.gnu.org/ml/gcc-help/2010-03/msg00114.html</a><br>
<br>Since the original author did such a great job explaining it, I'm just going to paste it here:<br><br>------<div><br>I have a function like<br><br>void myLog(const char *format, ...);<br><br>Now I want to let the compiler check the passed parameters if they fit to the format string like printf.<br>
I know this can be done easily with the following:<br><br>void myLog(const char *format, ...) __attribute__((format(printf, 1, 2)));<br><br>Now my problem is: I also want to accept the "%@" specifier that is accepted in Obj-C NSStrings or NSLog. The "%@" specifier accepts Obj-C objects (NSObject or id) or Core Foundation Object References (CFTypeRef).<br>
I saw that NSLog is declared this way:<br><br>void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));<br><br>Problem is that I don't have an NSString as format string parameter in my function. I have a plain old C-string (it should also work in C++ code, not only in Obj-C or Obj-C++ code). But it accepts the "%@" specifier (I am using Core Foundation in the Implementation under-the-hood).<br>
When I use the __NSString__ declaration like NSLog, gcc gives me an error message that my format parameter is not an NSString. Sure, it is not. But it doesn't matter. I just want gcc to do the format parameter checking like that.<br>
<br>Is there any chance to get gcc check my passed parameters the "Objective-C way" with "%@" included but still having the format string passed as plain old C-string? It there any other types than __NSString__ I could try?<br>
<br>--------</div><div><br></div><div>Any suggestions?</div><div><br></div><div>Cheers,</div><div>Dave</div></div>