Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLogging a memory address



On Wednesday, July 16, 2003, at 08:04 PM, The Amazing Llama wrote:

How can I get NSLog() to output the memory address that a given pointer is pointing to?

NSLog(@"%@<%x>", object, &object);

doesn't seem to work, as the area in brackets is not the same as the memory address displayed in the debugger. I know that I've seen this done, and I know that NSObject does it, but I can't remember the magic to do it.

In the above object is already a pointer, actually in general you cannot have Objective-C objects allocated on the stack. So you are always working with pointers if you are dealing with an Objective-C object. In other words no need to get the address of it because it is already an address.

I would use the following...

NSLog(@"%@ <%p>", object, object);

Using %p will insure that if the size of pointers change your output code will still be happy, at least in theory.

-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSLogging a memory address (From: The Amazing Llama <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.