This is the mail archive of the gcc@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]

Re: ObjC: attributes on methods


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


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