• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: [OT] Retain count riddle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [OT] Retain count riddle


  • Subject: RE: [OT] Retain count riddle
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Wed, 31 Mar 2004 19:05:04 +0200

At 15:31 Uhr -0500 30.03.2004, Jonathan E. Jackel wrote:
This should sorta work:

#define SAFE_SET_PATH(old, new) NSString *temp = [[new lastPathComponent]
retain]; [old release]; old = temp;

Two suggestions:

a) When you create a macro that contains several statements, use curly brackets to give it its own scope. this avoids namespace collisions and oddities when using the Macro in a one-line"if" without curlies.

b) Wherever you use a macro parameter, wrap it in parentheses to avoid precedence issues if it is an expression. So:

#define SAFE_SET_PATH(old,new) { NSString* temp = [new retain]; [old release]; old = temp; }

But of course, the smarter venue is always to not use macros for such stuff and instead use functions. IIRC C99 even brought us inline functions, which are a much better choice for such cases.

Macros are best only used when there is no other way to achieve something (e.g. if you need to paste together tokens for identifier names etc.)

Is it really so difficult to write proper accessors the long way, or use a
tool like Accessorizer? The benefit is that you can instantly debug
problems like this. Do you save enough effort using macros for that
practice to pay off?

You could also just turn on the Script menu in xCode. It contains two Perl scripts that take the selected variable declaration and create accessor declarations and definitions from that and put them on the clipboard.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >RE: [OT] Retain count riddle (From: "Jonathan E. Jackel" <email@hidden>)

  • Prev by Date: Re: Incompatible types error using vImage
  • Next by Date: Re: [Mom list] Mailing-list and Spam challenge
  • Previous by thread: RE: [OT] Retain count riddle
  • Next by thread: Generating accessor methods (was Re: [OT] Retain count riddle)
  • Index(es):
    • Date
    • Thread