php 的扩展原理就是函数的动态注入和调用,简单demo如下
head.h
=============
typedef struct function{
char * name;
void (* handler)();
} FUNCTION;
FUNCTION * function_list[10];
helloword.c
===========
#include <stdio.h>
#include "header.h"
int helloword(){
printf("%s","helloword");
}
FUNCTION f=
{
"helloword",
helloword
};
void get_module()
{
function_list[0] = &f;
}
maic.c
===============
#include <stdio.h>
#include "head.h"
extern void get_module();
int main(){
get_module();
function_list[0]->handler();
}