• 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: Confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confusion


  • Subject: Re: Confusion
  • From: "David P. Henderson" <email@hidden>
  • Date: Sun, 24 Jun 2001 19:05:47 -0400

'*' is not a pointer. It is notation used to designate that an identifier represents a reference to the location of a value. In other words, the identifier represents a pointer. I've always hated the way pointers are taught. Everyone immediately dives into memory address this and memory address that. The fact that in C a pointer refers to an address in memory is immaterial. It is an implementation detail which is not needed by novice programmers. Later knowing this detail will allow one to play all sorts of nasty tricks with pointers ;)

The important thing to understand about pointers is that they are references to the location of values, much like a book's table of contents or index or links on a web page. None of these are the values; they only tell you where to locate the value. Unlike other data types pointers are not the actual value, just a reference to it. For now don't get hung up on implementation details.

Objective-C is implemented on top of C. Objective-C knows about objects; C does not, at least not in the sense meant by OOP/D/A. Objective-C uses pointers to access its objects. An object is data which is capable of introspection. Objective-C shields you from needing to know all the gory details of the hows and whys of pointers. As someone else said, "Follow the rules, understanding will come." The thing you should be working on is recognizing what you are reading in code. You seem to be doing this fairly well.

'id' is a type defined by Objective-C to be a pointer to an object which is why you don't write it as: "id *myObject;".In Objective-C all objects are of type 'id', but for the purposes of the compiler and humans reading your code, you may declare that an object is of a specific class or that a method returns a specific type or that a method takes a specific type as an parameter.

When you create, return or pass an instance of a specific class, you need to explicitly use pointer notation. When you create, return or pass a generic object, you don't need to use explicit pointer notation since the language defines 'id' a pointer to an object. If it helps don't think of NSString *myString as a pointer, think of it as an instance of an NSString object. Because of the way Objective-C hides the implementation details for you, this is acceptable as long as you treat it as such.

Dave
--
Chaos Assembly Werks
"Nothing is too good to be true, except, perhaps, the morality of a bishop."
- Israel Zangwill


  • Follow-Ups:
    • Re: Confusion
      • From: Rosyna <email@hidden>
References: 
 >Confusion (From: email@hidden)

  • Prev by Date: Re: two quick questions: keychain and events
  • Next by Date: PB widget
  • Previous by thread: Re: Confusion
  • Next by thread: Re: Confusion
  • Index(es):
    • Date
    • Thread