# Can't find what '->' is used for.

• 01-01-2012
Mark Labarbara
Can't find what '->' is used for.
I am reading some code (K&R Questions=) but cannot figure out what '->' means. I have seen it a few times, and have tried searching around but have not come up with an answer. Just for an example, here is one instance where it is used.

[snippet]
Code:

```#include <stdio.h> #define MAXVAL 1000 #define MAXLINE 1000 typedef struct {     int top;     int val[MAXVAL];     int pos[MAXVAL]; } stackstr; /* very simple stack push function */ int push(stackstr *stk, int foo, int bar) {     if (stk->top == MAXVAL) {         printf("stack overflow. NOT putting more values on the stack.\n");         return 1;     }     stk->val[stk->top] = foo;     stk->pos[stk->top] = bar;     stk->top++;         return 0; }```
... [/snippet]
• 01-01-2012
CommonTater
When you need to access a value from a pointer to a struct, you have to use the -> notation... struct->value
When you have access to the struct directly you use the dot notation... struct.value

In the example you are working with a pointer to a struct... so....
• 01-01-2012
Mark Labarbara
Quote:

Originally Posted by CommonTater
When you need to access a value from a pointer to a struct, you have to use the -> notation... struct->value
When you have access to the struct directly you use the dot notation... struct.value

In the example you are working with a pointer to a struct... so....

Ah, makes sense why I have not come across them yet. I just finished my first college semester of C and the book we used, IMHO, was terrible (C programming for the Absolute Beginner).The teacher was actually even worse, she gave me a zero on an assignment once because she thought the source code was corrupted. By corrupted she mean't that when she opened the file in WordPad all the code was on one line.. I almost lost it. So, I went ahead and got 'The C programming language' by K&R, and I am basically relearning everything. There have been quite a few things already in the first chapter of K&R that were never even mentioned in the other book.

Appreciate the help, seems I will get there soon enough.
• 01-01-2012
CommonTater
Quote:

Originally Posted by Mark Labarbara
so I am basically relearning everything. There have been quite a few things already in the first chapter of K&R that were never even mentioned in the other book.

Appreciate the help, seems I will get there soon enough.

Also keep in mind that even the more advanced books like K&R don't cover everything... In the process of absorbing the fundimentals you will learn about perhaps 20 or 30 library functions and basic program structures... However the actual C standard library contains hundreds of functions, and many compilers also come with their own language extensions and extra libraries as well. Do yourself a favour and get the specific library documentation for your compiler... you will be glad you did and you'll need it to check syntax anyway.
• 01-01-2012
Mark Labarbara
Alright I will, should be easy, I use gcc lol.

• 01-01-2012
CommonTater
Quote:

Originally Posted by Mark Labarbara
Alright I will, should be easy, I use gcc lol.

GCC is very well documented... and far more capable than you'll find out from your books... Visit the website, download every document, man page and help file you can get your hands on... And get ready to be pleasantly surprised.
• 01-01-2012
Mark Labarbara
Quote:

Originally Posted by CommonTater
GCC is very well documented... and far more capable than you'll find out from your books... Visit the website, download every document, man page and help file you can get your hands on... And get ready to be pleasantly surprised.

Yeah I have been surfing that site since your last comment. However, I can't seem to find exactly what I think I am looking for. On this page it lists all of the documentation for every version. I found exactly what I want but for C++ (GCC 4.6.2 Standard C++ Library Manual) which goes through all of the standard C++ libraries and headers, etc.. Don't see the same for C.
• 01-01-2012
CommonTater
Quote:

Originally Posted by Mark Labarbara
Yeah I have been surfing that site since your last comment. However, I can't seem to find exactly what I think I am looking for. On this page it lists all of the documentation for every version. I found exactly what I want but for C++ (GCC 4.6.2 Standard C++ Library Manual) which goes through all of the standard C++ libraries and headers, etc.. Don't see the same for C.

Usually they're included in the C++ stuff for dual mode compilers... Look up some of the standard C headers... string.h, stdio.h etc...

But you also want the documentation on language extensions, etc. for the compiler itself.

Looking at the page, I'd want the GCC Manual, The CPP manual (which includes C) and the two C++ library manuals for a start.

Theres a lot more for C here... http://www.gnu.org/software/libc/manual/
• 01-01-2012
Mark Labarbara
Quote:

Originally Posted by CommonTater
Usually they're included in the C++ stuff for dual mode compilers... Look up some of the standard C headers... string.h, stdio.h etc...

But you also want the documentation on language extensions, etc. for the compiler itself.

Looking at the page, I'd want the GCC Manual, The CPP manual (which includes C) and the two C++ library manuals for a start.

Theres a lot more for C here... The GNU C Library - GNU Project - Free Software Foundation (FSF)

Awesome, thanks again!
I think I have enough to keep myself occupied till next semester starts :)