iDevGames Forums
memory pointer tricks? - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: memory pointer tricks? (/thread-1526.html)



memory pointer tricks? - Toontingy - Mar 30, 2009 09:58 PM

I am trying to port some code from C/C++ into Objective-C (doing iphone development) and I wondering if there is a comparable trick as the following:

memory = "foo 100bar";

x = atoi(&memory[0]);
here x is 0

x = atoi(&memory[4]);
here x is 100

Can something be done similar with NSString?


memory pointer tricks? - SethWillits - Mar 31, 2009 12:02 AM

If want memory access then use -[NSString UTF8String] or any of the other methods that get byte data from the string. If you want a substring, then use any of the methods that get a substring.

There's no tricks to be had.


memory pointer tricks? - Ingemar - Mar 31, 2009 02:35 AM

Toontingy Wrote:I am trying to port some code from C/C++ into Objective-C (doing iphone development) and I wondering if there is a comparable trick as the following:

memory = "foo 100bar";

x = atoi(&memory[0]);
here x is 0

x = atoi(&memory[4]);
here x is 100

Can something be done similar with NSString?
What is the "trick"? You are simply passing atoi a pointer to the beginning of the string (where there are no numbers) or to the fifth character, which is a number. In the first case, it finds nothing to interpret as a number, in the second case it does. Trick? This works the same in ObjC since it is straight C code.