C Wizards: What does this mean?

symphonix

Scratch & Sniff Committee
Hi all.

I'm trying to port some code from an open-source C program to Java (I'm working on a phase of the moon widget for Konfab) but I really don't know the C language, and am learning it from a textbook as I go.

Could somebody tell me what the "->" symbol means in this code snippet?

y = t->tw_year + 1900;

If somebody could tell me what it is, and if it has a Java equivalent, that would really help me out.
 
The -> is basically like . in Java for accessing a slot in a structure. Actually C also uses "." in the same way that Java does when you are directly manipulating the object. However, it is very common to use pointers to structures rather than structures directly so the "->" syntax is more convenient for that case.

If you want to be more confused the above line is just syntactic sugar for y = (*t).tw_year +1900;

That was lots of help huh... ;)

-Eric
 
The -> is the pointer de-referencing operator. Basically any time you have a pointer and want to access the object or structure it points to, you need to de-reference the pointer with that operator.

I don't think Java has pointers at all, so you can only pass references to an object.
 
Thanks guys. I think I'm starting to figure out what it means. I'm still wading throught the books but I figure I'll get the hang of it soon. Its just that -> isn't in the index, and since I didn't know what it related to, well, you get the picture.
Thanks for your help. :)
 
Back
Top