Click to See Complete Forum and Search --> : opaque pointer


George2
March 12th, 2008, 09:35 PM
Hello everyone,


Opaque pointer must be a pointer points to inner (hidden to outside) struct or class?

(refer to the C++ part)

http://en.wikipedia.org/wiki/Opaque_pointer


thanks in advance,
George

Lindley
March 12th, 2008, 09:45 PM
This technique can have pointers point to anything. The key observation is that the user of the class must be unable to discern or exploit anything about the inner workings of an object given only a handle to it.

In C, this might be done by handing back a void* which is only casted back to its actual type when it is passed to a function that knows what it is.

George2
March 12th, 2008, 10:05 PM
Thanks Lindley,


So, not a mandatory requirement for the wrapped pointer member to point to some inner structure? Could be any other global defined structure?

This technique can have pointers point to anything. The key observation is that the user of the class must be unable to discern or exploit anything about the inner workings of an object given only a handle to it.

In C, this might be done by handing back a void* which is only casted back to its actual type when it is passed to a function that knows what it is.


regards,
George

Lindley
March 12th, 2008, 10:08 PM
It's just a design pattern. Such things don't really have requirements, per se, they're simply useful notions that people have figured out and documented.

"We figured they was more guidelines, than actual rules."

George2
March 12th, 2008, 10:15 PM
Thanks Lindley,


Could you provide a deinite answer (yes or no) whether the wrapper pointer member must point to inner types (structs/classes) please?

Sometimes I am confused when people use this term.

It's just a design pattern. Such things don't really have requirements, per se, they're simply useful notions that people have figured out and documented.

"We figured they was more guidelines, than actual rules."


regards,
George

Paul McKenzie
March 13th, 2008, 02:40 AM
Thanks Lindley,


Could you provide a deinite answer (yes or no) whether the wrapper pointer member must point to inner types (structs/classes) please?There is no definite answer. The pointer could point to NULL or just an int, or whatever the coder(s) decide it to point to.

Are you planning to implement something using an opaque pointer?

Regards,

Paul McKenzie

George2
March 13th, 2008, 02:55 AM
Thanks Paul,


Sorry I have not made myself understood. My question is, for the opaque pointer design "pattern", the member pointer should be pointed to some inner data structure or global/namespace level data structure or both ok?

(ok I mean whether in this way, it could be called opaque pointer.)

There is no definite answer. The pointer could point to NULL or just an int, or whatever the coder(s) decide it to point to.

Are you planning to implement something using an opaque pointer?

Regards,

Paul McKenzie


regards,
George

Paul McKenzie
March 13th, 2008, 03:16 AM
Thanks Paul,


Sorry I have not made myself understood. My question is, for the opaque pointer design "pattern", the member pointer should be pointed to some inner data structure or global/namespace level data structure or both ok?And my answer is still the same. It is up to the designer as to what the pointer points to.

Regards,

Paul McKenzie

George2
March 13th, 2008, 03:29 AM
Thanks Paul,


Good to know it is not a must the pointer must be pointed to inner data structores for opaque pointer. :-)

And my answer is still the same. It is up to the designer as to what the pointer points to.

Regards,

Paul McKenzie


regards,
George