Questions tagged [opaque-pointers]

In computer programming, an opaque pointer is a special case of an opaque data type, a datatype declared to be a pointer to a record or data structure of some unspecified type.

Opaque pointers are a way to hide the implementation details of an interface from ordinary clients, so that the implementation may be changed without the need to recompile the modules using it. This benefits the programmer as well since a simple interface can be created, and most details can be hidden in another file. This is important for providing binary code compatibility through different versions of a shared library, for example.

86 questions
2
votes
3 answers

How to use struct declare

I want to hide the struct define, so I define struct in the source file, like this : //a.c #include "a.h" struct a_s { int a; int b; }; int func(a_t *a) { printf("%d\n", a->a); return 0; } and I declare the struct in the header…
sundq
  • 735
  • 2
  • 9
  • 28
2
votes
1 answer

When to use Pimpl pattern over Nested class in C++ or vice versa?

In C++ ,most of developers are using pimpl idiom or opaque pointers to hide the private data/implementation from the public API, for an example : => first case ## Opaque Pointer and PIMPL idiom ## // in header file class Node; class Graph { …
Buddhika Chaturanga
  • 957
  • 2
  • 14
  • 29
2
votes
1 answer

Putting opaque struct definition into a separate header file

I'm designing a library with a public interface containing opaque struct declaration: lib_public.h: typedef struct lib_struct lib_struct; void foo(lib_struct *ptr); void bar(lib_struct *ptr); The lib_struct opaque struct hides OS-specific…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
2
votes
1 answer

How to call C functions involving opaque pointers from Fortran 2003 correctly?

I'm learning Fortran 2003. As a training task, I'm trying to make calls from Fortran 2003 to a C library that uses opaque pointers: struct foobar_s; typedef struct foobar_s *foobar; foobar foo_create(enum foo, unsigned int); void…
aitap
  • 325
  • 1
  • 9
2
votes
1 answer

Initialize an AudioConverterRef Swift 3.0

var audioConverter : AudioConverterRef = nil audioConverter = AudioConverterRef.init() So basically I have the code above found from this StackOverflow answer that is using a previous version of Swift. Now in Swift 3.0 however the above initializer…
Chan Jing Hong
  • 2,251
  • 4
  • 22
  • 41
2
votes
2 answers

Opaque pointer to struct with template members

Suppose I'm building a linked list (the real data structure is completely different, but a linked list suffices for the question) whose nodes look like template struct node { struct node *next; T data; }; For my data structure,…
gspr
  • 11,144
  • 3
  • 41
  • 74
2
votes
1 answer

First time working with opaque pointers

I am trying to implement a stack, but am not understanding the use of the opaque pointer. Here is my declaration: /* incomplete type */ typedef struct stack_t *stack; /* create a new stack, have to call this first */ stack new_stack(void); And…
Connor
  • 269
  • 1
  • 4
  • 13
2
votes
2 answers

C - struct definition in header files

i have those two struct thats come with their header files. my struct number 1 is : header files 'list.h': typedef struct list * List; source files 'list.c' : struct list { unsigned length; char * value; }; my struct number 2 is : header…
Thapipo
  • 191
  • 3
  • 6
  • 16
2
votes
2 answers

Converting C declaration to Delphi XE2

I'm having trouble translating from some C declarations to Delphi XE2 for calling functions in a DLL. I translated all the function declarations from a Visual Basic source file, but in testing them I ran in to problems. Some functions returned Long…
ogalonzo
  • 37
  • 7
2
votes
2 answers

Opaque pointer in MSVC generates compiler error

main.c #include "stackg.h" int main() { return 0; } stackg.h #ifndef STACKG_H #define STACKG_H #ifdef __cplusplus extern "C" { #endif typedef struct stack_gt* stack_gt; stack_gt stkg_init( void* (*alloc)(const void* data,…
Jonas
  • 1,019
  • 4
  • 20
  • 33
2
votes
0 answers

Is there a way to make clang aware of custom opaque type reference counting?

I have some opaque types and have implemented a reference counting semantic that mimics Core Foundation. This works well enough except that clang warns me of semi valid potential leaks. MyTypeRef MyTypeRefCreateWithSomething(…) { MyTypeRef…
griotspeak
  • 13,022
  • 13
  • 43
  • 54
2
votes
1 answer

ID for objects of CGColorRef opaque type

I hope to understand internals of CoreFoundation objects with this research. Below given the structure of CGColor from free quartz project. typedef struct CGColor { CFRuntimeBase obj; CFTypeID nextID; CGColorSpaceRef…
lockedscope
  • 965
  • 17
  • 45
1
vote
2 answers

Obtaining xml data through an opaque pointer

I'm having an issue with retrieving an xml portion of a message using a vendor's api. As an example of what works: getDestination(void* message , void* destination, void* size) vendordestinationtype_t dest; getDestination(msg_p, &dest,…
Buraan
  • 13
  • 3
1
vote
1 answer

PyBind11 : share opaque pointers between independently-built C++ modules through Python

I have two PyBind11-linked Python modules which must compile separately (no common headers etc) and I would like to share pointers to a common custom C++ class defined the same way in both modules. I would like the pointers to be passed by a module…
1
vote
2 answers

Struggling with Opaque Pointers in SQLITE swift

Hi I am new to swift and attempting to add a database for my a level coding project. I cannot seem to get opaque pointers to work without errors. I have used tutorials and always get the same errors. The errors that I get: Expected member name or…
Josh Horne
  • 11
  • 4