ObjC: attributes on methods

Ziemowit Laski zlaski@apple.com
Mon Mar 11 00:32:00 GMT 2002


On Sunday, March 10, 2002, at 04:46 , Timothy J. Wood wrote:

>
>
>   It doesn't look like attributes can be applied to ObjC methods:
>
> @interface Foo
> + (void) printf: (const char *) fmt, ... __attribute__ ((format 
> (printf, 3, 4)));
> @end
>
>   Is there any major reason for this, or is it just because no one has 
> wanted it before?

The latter. :)  Well, I take that back -- I do recall seeing a feature 
request like this in the internal Apple database, the final goal being 
to have GCC type-check the arguments following the format string, just 
as for the ordinary "C" printf and friends.  (I assume this is what 
you're aiming at also, right?)

While I do see the appeal of this, I did manage to come up with a 
wrinkle.  Suppose that you have also defined

@interface Bar
+ (void) printf: (const char *)format, ...;
@end

WITHOUT the __attribute__(...) specification and then, somewhere else 
still, you constructed the message

    [someObj printf:"%s %d\n", arg1, arg2];

what should the compiler do?  In the general case, it won't be able to 
tell whether to perform the argument "type-checking" or not.

My thoughts,

--Zem



More information about the Gcc mailing list