Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

strange warning with NSArray

3 views
Skip to first unread message

Martin Hammerschmied

unread,
Jul 10, 2008, 9:53:00 AM7/10/08
to
hi!

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:@"+"]];

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:@"+"]];

i get a warning: passing argument 1 of 'addObject:' from incompatible
pointer type

anyone a guess?

Gregory Weston

unread,
Jul 10, 2008, 12:54:07 PM7/10/08
to
In article <bbd6e$4876143c$54771a3e$24...@news.inode.at>,
Martin Hammerschmied <mar...@sbox.tugraz.at> 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.

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

David Phillip Oster

unread,
Jul 14, 2008, 1:01:14 AM7/14/08
to
In article <bbd6e$4876143c$54771a3e$24...@news.inode.at>,
Martin Hammerschmied <mar...@sbox.tugraz.at> wrote:

Guesses:

1.) You made an error: you declared initOperatorType: as returning
something other than (id). All inits should return id. Probably
(Operator *)

2.) You made a second error. In your @interface declaration for whatever
class you declared initOperatorType as returning, you didn't derive from
NSObject:

@interface Operator : NSObject // <- forgotten?
...
@end

Just guesses. Am I close?
--
David Phillip Oster

0 new messages