Works for me.

-(void)aMethod:(void *)mem {
        NSLog(@"mem2: %d", mem);
}


- (void)awakeFromNib {
        void *memory = malloc(1);
        NSLog(@"mem1: %d", memory);
        [self aMethod:memory];
}

2008-10-16 11:40:36.815 aProg[30378:813] mem1: 2439440
2008-10-16 11:40:36.815 aProg[30378:813] mem2: 2439440


--- On Wed, 10/15/08, James Trankelson <[EMAIL PROTECTED]> wrote:

> From: James Trankelson <[EMAIL PROTECTED]>
> Subject: Objective-C parameter mutation
> To: "cocoadev List" <Cocoa-dev@lists.apple.com>
> Date: Wednesday, October 15, 2008, 5:31 PM
> Hi,
> 
> I have a question about method parameters in Objective C. A
> long time
> ago, I had a method like the following:
> 
> -(void) foo:(float)val { }
> 
> ... and when I would call it ([inst foo:0.001], for
> example), the
> value inside the foo method would NOT be 0.001. At the
> time, I
> believed there to be an Objective C requirement that
> parameters to
> methods need to be pointers to objects, not primitive
> values. So, I
> achieved success by changing the above method declaration
> to
> 
> -(void) foo:(NSNumber*)val { }
> 
> ... and passing in a NSNumber* with a float value worked.
> 
> Now, I'm having the same problem, but am not convinced
> there is any
> such requirement that parameters be pointers to object
> instances. (I
> could be wrong, though)
> 
> So, I've got the following method:
> 
> + (void)done:(MyObj*)dObj structure:(void*)pStruct
> 
> ... and when I call it with a "structure"
> parameter, say a malloc'ed
> char* at address 0x171eb070, as soon as I step into this
> method, the
> address is no longer 0x171eb070, but some garbage value
> that causes
> all sorts of trouble. Here's to hoping someone can tell
> me why this
> doesn't work...
> 
> Thanks
> 
> jt
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to
> the list.
> Contact the moderators at
> cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/idou747%40yahoo.com
> 
> This email sent to [EMAIL PROTECTED]


      
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to