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

Re: ObjC question


  • Subject: Re: ObjC question
  • From: Tony Romano <email@hidden>
  • Date: Mon, 21 Feb 2011 13:36:31 -0800
  • Thread-topic: ObjC question

Yep, I will join that list.

You example will pass in the address of the local variable and not the one contained in the object(I.e the address is off the stack and not in the memory space of the object).  I wouldn't use the term smelly :-).  What I am trying to do is pass in a reference to a pointer.  The code is from an insert routine for a btree, recursive version to make it a bit clearer of my intentions. 

Tony Romano

From: Quincey Morris <email@hidden>
Date: Mon, 21 Feb 2011 13:07:11 -0800
To: Tony Romano <email@hidden>
Cc: XCode Apple <email@hidden>
Subject: Re: ObjC question

On Feb 21, 2011, at 12:19, Tony Romano wrote:

I'm trying to do this:

-(void) insert: (BTreeNode **) node node:(BTreeNode *) n
{
…

// get the address of the left member 
[self insert:&[(*node) left] node:n];  // <--- error
}

The compiler(GCC 4.2 or LLVM 1.6) is giving this error : address _expression_ must be an lvalue or a function designator.

I was assuming the return value for [[(*node) left]] is a lvalue (it's a pointer) and I should be able to obtain the address of that pointer but either you can't or the value returned from the message call to node is not a lvalue.

You're all tangled up. A return value is *never* a lvalue (if it was, you could write 'sqrt (4) = 3;'), so you're going to have to do this:

BTreeNode *temp = [(*node) left];
[self insert:&temp node:n];

but your code is still very smelly because it's not clear why you're passing around a pointer to the pointer to the left node (BTreeNode **). If the intention is to have 'insert:node:' return the left node pointer to its caller, why not just use a return value?

BTW, this the wrong list for this question, since it's not about Xcode. The correct list is probably email@hidden.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: ObjC question
      • From: Marshall Clow <email@hidden>
References: 
 >Re: ObjC question (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: ObjC question
  • Next by Date: Re: ObjC question
  • Previous by thread: Re: ObjC question
  • Next by thread: Re: ObjC question
  • Index(es):
    • Date
    • Thread