Re:Null Pointer Dereferencing Causes Undefined Behavior
by ehmmm on Tuesday April 21, 2015 @12:41AM
(#9412313)
Clearly, you don't have anything constructive to say, so you have to resort to ad hominem.
[] operator doesn't have any place in this debate.
Re:Null Pointer Dereferencing Causes Undefined Behavior
by spoiler on Tuesday April 21, 2015 @06:16AM
(#9413094)
Well, as far as I understand it, `->` works in a similar fashion to `[]`; the difference being that one behaves on arrays while the other on structs.
What @jwatte tried to say is that `->` works like this:
// foo is struct thingity*
&foo->bar == foo + offsetof(struct thingity, bar);
The `[]` does a similar thing: // s is char*
*(s+i) == s[i]
Re:Null Pointer Dereferencing Causes Undefined Behavior
by ehmmm on Tuesday April 21, 2015 @08:42PM
(#9418042)
Sure, &foo->bar looks like foo + offsetof(struct thingity, bar), but there is no pointer arithmetic involved since C doesn't specify how the member access ( -> or . ) is actually calculated.
It does however specify that [] operator is equivalent to pointer arithmetic. But we are talking ->,. operators and not [].
If you look at the definition of the -> and [], you might learn something!