On 25. Mrz 2006, at 12:51 Uhr, Günther Noack wrote:
Am 25.03.2006 um 00:57 schrieb Adrian Robert:
But it's only a warning -- it still works at runtime in either case. What is the compiler doing differently with the cast? Is it some performance optimization?
The resulting code doesn't differ.

If you have those methods:

  @implementation C:
  - (void)addNumber:(float)value;

  @implementation A:
  - (void)addNumber:(short)value;

  @implementation B:
  - (void)addNumber:(NSNumber *)value;

The generated code of course _does_ differ. How exactly it differs depends on the C ABI of the host system.

This is why its recommended to explicitly include the type in the method for base type stuff, like:
  - (unsigned int)unsignedIntValue;
  - (id)initWithUnsignedInt:(unsigned int)value;
etc.


The problem is a bit less when both methods take objects as arguments, like:

  @implementation C:
  - (void)addNumber:(NSNumber *)value;

  @implementation A:
  - (void)addNumber:(NSValue *)value;

Of course in this case the generated code is the same. However, the static type checking being applied is the same in the C compiler. And the reason why the compiler needs to do type checking is also the same.

If you want to accept arbitary objects with your selector, use just
  - (void)addNumber:(id)value;

Which is the 'traditional' ObjC way :-)

Greets,
  Helge
--
http://docs.opengroupware.org/Members/helge/
OpenGroupware.org



_______________________________________________
Discuss-gnustep mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnustep

Reply via email to