* Accepting "%@" in format string with __attribute__ format
@ 2010-03-09 13:45 Manfred Schwind
2010-03-09 15:05 ` Cedric Roux
2010-03-10 15:54 ` Ian Lance Taylor
0 siblings, 2 replies; 3+ messages in thread
From: Manfred Schwind @ 2010-03-09 13:45 UTC (permalink / raw)
To: GCC-Help Mailing List
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Accepting "%@" in format string with __attribute__ format
2010-03-09 13:45 Accepting "%@" in format string with __attribute__ format Manfred Schwind
@ 2010-03-09 15:05 ` Cedric Roux
2010-03-10 15:54 ` Ian Lance Taylor
1 sibling, 0 replies; 3+ messages in thread
From: Cedric Roux @ 2010-03-09 15:05 UTC (permalink / raw)
To: Manfred Schwind; +Cc: GCC-Help Mailing List
Manfred Schwind wrote:
> 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(...))) ?
This NSString does not seem to be recognized by gcc at all.
I see that llvm handles it.
(http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?revision=97103&view=markup)
Are you sure you use gcc?
Compiling:
#import <Foundation/Foundation.h>
void mlog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
leads to:
toto.m:3: warning: ‘__NSString__’ is an unrecognized format function type
with gcc 4.4 and GNUstep stuff.
Apart from that, the gcc documentation tells what types you can use in __attribute__ format
stuff. (Here when I do "info gcc", in the C Extensions -> Function Attributes it is
described and allowed stuff is:
`printf', `scanf', `strftime',
`gnu_printf', `gnu_scanf', `gnu_strftime' or `strfmon'. (You can
also use `__printf__', `__scanf__', `__strftime__' or
`__strfmon__'.) On MinGW targets, `ms_printf', `ms_scanf', and
`ms_strftime' are also present.
)
My .1 euros...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Accepting "%@" in format string with __attribute__ format
2010-03-09 13:45 Accepting "%@" in format string with __attribute__ format Manfred Schwind
2010-03-09 15:05 ` Cedric Roux
@ 2010-03-10 15:54 ` Ian Lance Taylor
1 sibling, 0 replies; 3+ messages in thread
From: Ian Lance Taylor @ 2010-03-10 15:54 UTC (permalink / raw)
To: Manfred Schwind; +Cc: GCC-Help Mailing List
Manfred Schwind <lists@mani.de> writes:
> 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?
Unfortunately I don't think this is possible. Over the years there
have been various proposals for extending the printf format checking,
but nothing has been widely accepted or implemented.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-03-10 15:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-09 13:45 Accepting "%@" in format string with __attribute__ format Manfred Schwind
2010-03-09 15:05 ` Cedric Roux
2010-03-10 15:54 ` Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).