Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Objective-c > Re: strange war...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 1004 of 1039
Post > Topic >>

Re: strange warning with NSArray

by Gregory Weston <uce@[EMAIL PROTECTED] > Jul 10, 2008 at 12:54 PM

In article <bbd6e$4876143c$54771a3e$24695@[EMAIL PROTECTED]
>,
 Martin Hammerschmied <marvel@[EMAIL PROTECTED]
> wrote:

> hi!

Hi. A little advice up front: This isn't strictly an appropriate 
newsgroup. You're asking for help with a specific class library on a 
group dedicated to a language. In the future, I'd recommend posting such 
questions to comp.sys.mac.programmer.* groups. They're more appropriate 
*and* offer the benefit of more eyeballs looking at your question.

> i'm having a strange warning here. the following code works fine:
> 
> operators = [[NSMutableArray alloc] init];
> 
> Add * test = [Add alloc];
>
> [operators addObject:[test initOperatorType:OPERATOR_TYPE 
> priority:ADDITIVE_OPERATOR_PRIORITY symbol:@[EMAIL PROTECTED]
"+"]];
> 
> on the other hand if i merge the last two lines like this:
> 
> [operators addObject:[[Add alloc] initOperatorType:OPERATOR_TYPE 
> priority:ADDITIVE_OPERATOR_PRIORITY symbol:@[EMAIL PROTECTED]
"+"]];
> 
> i get a warning: passing argument 1 of 'addObject:' from incompatible 
> pointer type
> 
> anyone a guess?

The way that "works" is a coding error. The variable 'test' points to a 
chunk of memory that has been allocated and had only the most basic 
initialization performed - enough to tell it that it's an 'Add' instance 
and that's about it. Since there can be some odd side effects of 
separating allocation and initialization, I wouldn't really trust the 
fact that it works. I'd be more inclined to say the error you get when 
doing it the right way is indicative of something hinky that should be 
fixed.

Having said that, it's hard to tell what's really going wrong without 
more information. I can't manufacture a situation the exhibits what 
you're seeing. How is your initializer declared? (And, for that matter, 
defined?) Do you get any warnings? What happens if you switch around the 
first example so the alloc/init happen together and then pass the fully 
constructed object to addObject:?

-- 
"Harry?" Ron's voice was a mere whisper. "Do you smell something ...
burning?"
   - Harry Potter and the Odor of the Phoenix
 




 3 Posts in Topic:
strange warning with NSArray
Martin Hammerschmied <  2008-07-10 15:53:00 
Re: strange warning with NSArray
Gregory Weston <uce@[E  2008-07-10 12:54:07 
Re: strange warning with NSArray
David Phillip Oster <o  2008-07-13 22:01:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 7 7:35:43 CDT 2008.