gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFI]: getting objc to grok attributes ??


From: Nicola Pero
Subject: Re: [RFI]: getting objc to grok attributes ??
Date: Mon, 17 Jun 2002 11:06:56 +0100 (BST)

> I was trying to fix these warnings:
> 
>  > libobjc/Object.m:273: warning: unused parameter `argFrame'
>  > libobjc/Object.m:366: warning: unused parameter `aStream'
>  > libobjc/Object.m:372: warning: unused parameter `aStream'
> 
> But when I put in attribute "unused", I get parser errors.  I tried to
> fix the objc parser, and I got it to accept the attributes.  However
> it does nothing with them and the warnings remain.

Hi Kaveh

Thanks for looking into this :-) looks like very technical.

May I give you a help with the ObjC part and suggest - not how to
implement - but maybe what to implement :-)

I think it's very common in ObjC to have implementation of methods which
ignore the arguments of the methods.  I'm not sure what the semantics of
__attribute__((__unused__)) would be, but in general it's probably better
to do without it and remove the warnings from the compiler instead! :-)

The reason is that, while in C you define a function and normally the
function has a single implementation associated with it (so, if an
argument is unused, it's suspicious that there might be a mismatch between
the declaration and the implementation, and it's a good idea to warn), in
ObjC is very common to define a method in a place and have many different
implementations of the method in many different classes.  For example -

 - you override the superclass' methods in subclasses.  it often happens
that an argument which the superclass needs can be ignored by a subclass.

 - you have the same method implemented by different classes.  because
ObjC does dynamic binding, this is standard usage.  often, these methods
which are shared or follow standard conventions, have some arguments which
are sort of optional - they are needed by some implementors, but not by
others, and they are included in the method definition because the same
declaration needs to be used by both (for example, in OpenStep when you
click a button, the button executes the action [a method] of a target
object.  This method takes an argument, which is the button having been
pushed; this argument is often ignored, but it's included because in some
special cases it's useful and can't be done without.  Now you don't want
to issue a warning each time this argument is unused.).

So I would consider the case of an unused argument of an ObjC method a
completely different case of an unused argument of a C function.  It's
standard practice to have unused arguments in ObjC methods.

Also, when you declare a method, you don't know all its implementations.  
Subclasses (even future subclasses yet to be written) might provide new
implementations, some of which might need to ignore one of the arguments.  
Which is perfectly fine and normal.

Depending on the semantics of __attribute__ ((__unused__)) [does it mark
the argument as being possibly unused in that method implementation, or is
it a system-wide declaration that in all implementations of methods with
that name/signature the argument could be unused ?], it might be extremely
bad (if it's a wide argument, you would likely have to mark every argument
of an ObjC method with __attribute__ ((__unused__)), since it is always
possible that a new subclass will override that method ignoring the
arguments, and if they can't override superclass' declaration), or
moderately bad (if it's local to that specific implementation).

So, maybe (from an ObjC user point of view) we should better disable the
warnings for unused method arguments, unless some -Wxxx option is included
to cause them (my bet is nobody will ever want to use that option, but
anyway).

We should of course keep the warnings for unused arguments of functions,
all that is like in C and it's very useful.

Hope my comments are of some use.  Comments from others are of course
welcome.

Thanks for your work! :-)


> I can't figure out what to do with the attribute once the parser gets
> a hold of it.  Can someone please explain it to me?
> 
>               Thanks,
>               --Kaveh
> 
> Here's my "wild guess" parser patch along with the attributes I'm
> trying to add.  I don't know objc, I got this far by trial and error.
> Apologies if I'm on the wrong track.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]