• 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: C question for you old guys ;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C question for you old guys ;-)


  • Subject: Re: C question for you old guys ;-)
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 9 Jun 2003 11:43:27 -0700

On Monday, June 9, 2003, at 10:49 AM, Dan Sugalski wrote:

At 9:49 AM -0700 6/9/03, John C. Randolph wrote:
On Monday, June 9, 2003, at 05:43 AM, Dan Sugalski wrote:
It catches the times when I miss a = in the test--"NULL = foo" throws a compile-time error, "foo = NULL" leads to a bughunt >>> session.

#define is ==

if (spriteInfo is NULL)

.. ever since I started doing this, I've never assigned when I meant to compare.

When I do C things, I try hard not to warp the syntax of the language like that.

When I use the preprocessor, I do so to make the code more legible and obvious.

When I write

#define is ==
#define and &&
#define or ||
#define until(a) while(!(a))

I eliminate a large number of errors that compile without complaint.

The only time this has ever caused a problem was when someone else used an obj-C method name that included the token 'and:', and the preprocessor substituted &&, turning it into '&&:'. I would contend that this was a tokenizer bug, since taking 'and' instead of 'and:' as the token violated the maximal-munch rule. At any rate, it was trivial to work around.

FWIW, I never compare to nil or NULL in a boolean expression. My old C habits would actually lead me to use

if (!spriteInfo)
...

In the case at hand.

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.

  • Follow-Ups:
    • Re: C question for you old guys ;-)
      • From: Andy Lee <email@hidden>
References: 
 >Re: C question for you old guys ;-) (From: Dan Sugalski <email@hidden>)

  • Prev by Date: [OT] Where to get short sounds?
  • Next by Date: Re: Good Habits (was: Re: C question for you old guys ;-))
  • Previous by thread: Re: C question for you old guys ;-)
  • Next by thread: Re: C question for you old guys ;-)
  • Index(es):
    • Date
    • Thread