Jump to content
  • Advertisement
Sign in to follow this  
uutee

Three-level pointer indirection - any usages?

This topic is 4620 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been playing around with this theory that the reason that most coders are accustomed to at max two-level pointer indirection, e.g. void safe_delete( int** p ) { delete *p; *p = 0; } is that the "practical world" doesn't expose us to problems that require more than two-level pointer indirection. But then again, having an intuitive grasp of multi-level pointer indirection, might embetter one as a programmer. So I thought: perhaps one could come up with practical examples of three-level pointer indirection. So basically I'm asking; have you ever seen (or have come up with) code that practically requires something like "int*** p", assuming this is just a pointer-to-pointer-to-pointer-to-integer, and has nothing to do with arrays? Thanks, - Mikko

Share this post


Link to post
Share on other sites
Advertisement
It happens, although it's not exactly common. But the first few levels will generally be wrapped up in a typedef or structure anyway, so you're still not doing it conceptually.
As for concrete examples, I can't think of anything off-hand..

Share this post


Link to post
Share on other sites
Can't think of anything besides kSquared's example. But conceptually there isn't that much difference between single-, double- or multi-level indirection anyway.

Illco

Share this post


Link to post
Share on other sites
I don't think I've ever seen more than two levels of indirection unless there was an array in there somewhere. Admittedly, I've seen some really ugly indirections involving arrays.

Share this post


Link to post
Share on other sites
The only times I ever used double-indirection with pointers is when I need to pass a pointer into a creation function, and have it point to the created object, and even in that case, I tend to pass a reference to a pointer instead or a pointer to pointer, as it makes things easier to read and understand, I feel. I can't think of an example that would use triple indirection offhand.

Share this post


Link to post
Share on other sites
2D array of pointers is one. In fact, if you wanted to pass a the pointer to the 2D array of pointers to a function so that it would be altered to point to a different 2D array of pointers you could have quadruple indirection.

Above double indirection it becomes progressively more irritating to allocate and deallocate with nested loops and so forth though, so this is a further reason (other than the dereferencing confusion) why it is not normally done.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!