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

Cookbook Chapter 5: Calling C++ Virtual Functions. More...

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

Functions

int main ()
 

Variables

const char * LIB_NAME = "./libshapes.so"
 

Detailed Description

Cookbook Chapter 5: Calling C++ Virtual Functions.

This example demonstrates how to call a C++ virtual function from C without any wrappers. This is achieved by emulating the compiler's v-table dispatch mechanism:

  1. Read the hidden v-table pointer (vptr) from the object's memory.
  2. Read the function pointer from the v-table at its known index.
  3. Use infix to call that function pointer, passing the object as the first ('this') argument.

Function Documentation

◆ main()

int main ( void  )

Variable Documentation

◆ LIB_NAME

const char* LIB_NAME = "./libshapes.so"