Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
The book gave me a choice as to which one to use to access a field in a Struct after I passed a pointer of the struct as a parameter (I hope I said all that right).

(*myPtr).number

or

myPtr->number

It says both are the same but I remember looking over a little Objective C code and I saw people using the (dot). Will both of these work on Objective-C since it is built on top of C or use the (dot) version if my next step is Object-C? The book said more people programing in C use this version myPtr->number.

-Lars
 
Only worry about C right now. All C is Objective-C. Structs behave exactly the same. With an object in Objective-C there is a . syntax for accessing properties, which is just syntactic sugar for a message pass. None of that is relevant to you right now. When you have a struct the . operator gets you a member. When you have a pointer to a struct -> gets you a member. * will dereference a pointer to a struct so you have a struct so you can use . to access a member.

If you have a pointer to a struct you can dereference and dot or arrow. You'll get the same result.

-Lee
 
The book gave me a choice as to which one to use to access a field in a Struct after I passed a pointer of the struct as a parameter (I hope I said all that right).

(*myPtr).number

or

myPtr->number

It says both are the same but I remember looking over a little Objective C code and I saw people using the (dot). Will both of these work on Objective-C since it is built on top of C or use the (dot) version if my next step is Object-C? The book said more people programing in C use this version myPtr->number.

-Lars

For the sake of any programmers reading your code use myPtr->number :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.