Pointers?

Started by
15 comments, last by jedis1000 20 years, 1 month ago
quote:Original post by Oluseyi
No, it''s two characters instead of one, redundant and ugly.


That''s fully subjective.
Advertisement
quote:Original post by RuneLancer
That''s fully subjective.
Then how about "it''s confusing; having a single member access operator regardless of reference type creates no ambiguity"?
You know, as a moderator, one would expect a little more maturity.

Let''s try to stick to the OP''s question, shall we?
quote:Original post by RuneLancer
You know, as a moderator, one would expect a little more maturity.
What does that even mean? You made a subjective, inaccurate comment and I refuted it, then you accuse me of "immaturity"? Is it suddenly cool to bash moderators or what?

There is no valid reason to have two member reference operators. The D programming language has shown that implementing a single operator is possible (and trivial). Indeed, the ambiguity created by the presence of two different means of getting at the same thing has spawned entire threads on the topic. Granted, it''s a feature of the language, but it''s not a good one - nor is it "cooler", as you allude: it''s twice as many characters, inconsistent with any other programming language and has no redeeming features.

Since I''m a nice guy, let me say this clearly: I''m getting tired of taking flak from ignorant posters. Don''t make me vindictive; it''s never pretty.
I suggest you drop the matter. You really ARE making yourself look immature by trying to drive in a point that not only has little to no relevance to the OP''s question, but is also truly a matter of personal preference that has very little impact on a program''s final performance. Moderator or not. Furthermore, I fail to see where this is going. Peace.

To return to the OP''s question, no-one has brought up function pointers. That''s an other application pointers get, though it''s less frequent than using them to manage dynamic variables. You can create a reference to a function and call that function, then change the pointer on the fly to call an other function. They can be used to replace switch/if statements (not sure you''d want to do that though; you''d probably take performance hits and your could would most likely lose clarity anyways), realize late-binding, or implement callbacks.

Although you can find much better ways to replace function pointers and probably won''t need them, there are still a number of uses for them in C.
quote:Original post by Oluseyi
There is no valid reason to have two member reference operators. The D programming language has shown that implementing a single operator is possible (and trivial).


As has Java, yes?
The reason we use pointers is so that we can keep anonymous things around in arbritary quantity.

These are normally used (in the context of games) for anything which there is likely to be >1 of at once, for example, the bad guys, or items on a level.

We don''t want to have a fixed maximum number of them (like if we used a normal array) - so we''d normally use a linked list (or indirectly, through STL).

Additionally, we can use them as references, when we have one item of some kind which needs to remember some relationship to some other item - like a guided missile remembering what its target is. That way, it doesn''t need to try and find a new target each time around the main loop, it can just keep aiming at the same one.

In practice this is very common in games, we have RPGs where everyone belongs to a party, and monsters are chasing a target, items belong to people, NPCs have things too, so in practice we tend to use pointers a lot.

Mark

This topic is closed to new replies.

Advertisement