This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Accepting "%@" in format string with __attribute__ format


Hi,

I have a function like

void myLog(const char *format, ...);

Now I want to let the compiler check the passed parameters if they fit to the format string like printf.
I know this can be done easily with the following:

void myLog(const char *format, ...) __attribute__((format(printf, 1, 2)));

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).
I saw that NSLog is declared this way:

void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));

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).
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.

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?

BTW, is there an official list what types are accepted by __attribute__((format(...))) ?

Thanks,
Mani
--
http://mani.de - friendly software
iVolume - listen to music hands-free
LittleSecrets - the encrypted notepad


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]