infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Ch04_VTableCStyle.c File Reference

Cookbook Chapter 4: Calling a Function Pointer from a Struct. More...

#include <infix/infix.h>
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for Ch04_VTableCStyle.c:

Classes

struct  Adder
struct  AdderVTable_t

Typedefs

typedef struct AdderVTable_t AdderVTable

Functions

static int vtable_add (Adder *self, int amount)
static void vtable_destroy (Adder *self)
static Adder * create_adder (int base)
int main ()

Variables

const AdderVTable VTABLE = {vtable_add, vtable_destroy}

Detailed Description

Cookbook Chapter 4: Calling a Function Pointer from a Struct.

This example demonstrates how to call a function pointer that is a member of a struct. This pattern is common in C for emulating object-oriented v-tables or for creating plugin interfaces.

The process is two-step:

  1. Read the function pointer from the C struct.
  2. Create an infix forward trampoline for that specific function pointer's signature and call it.

Typedef Documentation

◆ AdderVTable

typedef struct AdderVTable_t AdderVTable

Function Documentation

◆ create_adder()

Adder * create_adder ( int base)
static

◆ main()

int main ( void )

◆ vtable_add()

int vtable_add ( Adder * self,
int amount )
static

◆ vtable_destroy()

void vtable_destroy ( Adder * self)
static

Variable Documentation

◆ VTABLE