What does -> mean in the following line of code?

bulk_in=end_point->bEndpointAddress;

My books show - and > but neither of them seem to apply. The books don't seem to show both together. This is part of a USB driver that I'm trying to convert from Linux to C for the PIC processors. (USB class TMC. Microchip has USB drivers but not for the Test and Measurement Class.)

According to a post on stackoverflow:

The dot (.) operator is used to access a member of a struct, while the arrow operator (->) in C is used to access a member of a struct which is referenced by the pointer in question.

The pointer itself does not have any members which could be accessed with the dot operator (it's acually only a number describing a location in virtual memory so it doesn't have any members). So, there would be no ambiguity if we just defined the dot operator to automatically dereference the pointer if it is used on a pointer (an information which is known to the compiler at compile time afaik).

pointerToSomeObject->aMemberFunctionOfThatObject

is the same as

*(pointerToSomeObject).aMemberFunctionOfThatObject

-> is just shorthand for "dereference this pointer, and then give me this member function/variable.

I prefer dereferencing using -> because it's simpler and doesn't make me think about it. Similar to a native English speaking person reading code written in English instead of some other language that has to be translated into English. Both might do the same thing, but one is more easily read than the other. And that's one of the big purposes you want to achieve with the code you write -- make it understandable, not cute.

My books show - and > but neither of them seem to apply. The books don't seem to show both together.

Strange books. -> is a single token, and should at the very least be mentioned in the precedence table for operators.

Thanks people. You're all very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.