top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is opaque pointer?

0 votes
492 views
What is opaque pointer?
posted May 31, 2014 by Kali Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

An opaque pointer is one in which no details are revealed of the underlying data For example, you may declare in a header file

typedef struct mystruct *p_mystruct;

which declares a type p_mystruct which is a pointer to the opaque structure struct mystruct, hence anything you declare as p_mystruct will be an opaque pointer.

Users can write code like:

p_mystruct x = NULL;
answer Jun 1, 2014 by Santosh Prasad
Good explanation.
0 votes

An opaque pointer is the pointer for which programmer cannot get the internal of the variable it points (means internal of the variable being accessed is hidden). There are many ways to achieve this:

  1. Use void * pointer to access the structure. Problem with this approach is that user cannot use statically allocated variable of the structure. HANDLE in Win32 is implemented in this way.
  2. Declare a structure with padding of chars in the header file which will give it same size as of the original structure. In the implementation code, use the structure directly. In this approach, user will not get any hint of the internal of the structure, but can declare statically allocated variable of the structure. pthread_t is implemented in most the cases like this.
answer Jun 1, 2014 by Devender Mishra
Similar Questions
+1 vote

What type of conversion is not accepted in C and why?
a) char to int
b) float to char pointer
c) int to char
d) double to char

0 votes

What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?

...