Is it ok to use . as a member qualifier instead of the symbol -> for structures in GNU c. The compiler does not complain when symbol . used in place of ->.
Asked
Active
Viewed 70 times
-1
-
2Please show some code, your terminology usage is non-standard. – unwind Feb 19 '19 at 13:18
-
4`.` is used to access members of a structure; `->` is used to access members of a structure pointed to. The latter dereferences the pointer and then gets the member. So `p->x` is equivalent to `(*p).x` – Paul Ogilvie Feb 19 '19 at 13:19
-
Possible duplicate of [Arrow operator (->) usage in C](https://stackoverflow.com/questions/2575048/arrow-operator-usage-in-c) – Sander De Dycker Feb 19 '19 at 14:10
1 Answers
4
.
is used to access members of a structure; ->
is used to access members of a structure pointed to. The latter dereferences the pointer and then gets the member. So p->x
is equivalent to (*p).x
. Example:
struct P {
int x;
int y;
};
struct P myP = {1,2};
struct P *p= &myP;
printf("%d, %d\n", myP.x, myP.y); // prints 1, 2
printf("%d, %d\n", p->x, p->y); // prints the same
printf("%d, %d\n", (*p).x, (*p).y); // is the same

Paul Ogilvie
- 25,048
- 4
- 23
- 41