averageint library

Src folder list: here

Opaque pointers

For information hiding https://en.wikipedia.org/wiki/Opaque_pointer

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

Opaque pointers are present in several programming languages including Ada, C, C++, D and Modula-2.
Use

If the language the pointer is implemented with is strongly typed, programs and procedures that have no other information about an opaque pointer type T can still declare variables, arrays, and record fields of type T, assign values of that type, and compare those values for equality.
However, they will not be able to de-reference such a pointer, and can only change the object's content by calling some procedure that has the missing information.

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.[1] This is important for providing binary code compatibility through different versions of a shared library, for example.

This technique is described in Design Patterns as the Bridge pattern.
It is sometimes referred to as "handle classes",[2] the "Pimpl idiom" (for "pointer to implementation idiom"),[3] "Compiler firewall idiom",[4] "d-pointer" or "Cheshire Cat", especially among the C++ community.[2] It is heavily used in the Qt[5] and KDE[6] libraries.

The two files for the library  .h and .c - excuse for having a min in Integer.c for testing

If Integer.c is hidden or only avilable as binary user cant see the code

Integer.h
=========

#pragma once

#include 

typedef struct Integer Integer;  // here we hide content for user

/*
 * The compiler considers struct Integer an incomplete type. Incomplete types
 * can be used in declarations.
 */

size_t integerSize();

void integerSetValue(Integer* i, int val);

int integerGetValue(Integer* i);


Integer.c
=========

#include "Integer.h"

typedef struct Integer {
    int value;
} Integer;

/*
 * The caller will handle allocation.
 * Provide the required information only
 */

size_t integerSize() {
    return sizeof(Integer);
}

void integerSetValue(Integer* i, int val) {
    i->value = val;
}

int integerGetValue(Integer* i) {
    return i->value;
}

int main()
{}


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.h


#ifndef FOO_H
#define FOO_H

typedef struct foo foo; // forward declaration
foo *foo_create();
void foo_destroy(foo *f);
#endif



.c -----

#include 
#include "foo.h"

struct foo {
   int data;
};

foo *foo_create() {
   return calloc(1, sizeof(foo));
}

void foo_destroy(foo *f) {
   free(f);
}