C语言不透明结构体实现

在头文件中typedef, 具体实现在c文件中,这样外部文件便无法访问此模块内的数据。

/***************************************
 * struct.h
 ***************************************/

typedef struct my_struct my_struct;

void my_function(int my_g_handler,  my_struct *s, void *user_data);

/****************************************
 * struct.c
 ****************************************/
#include "struct.h" struct my_struct { int element1; int element2; }; void my_function(int my_g_handler, my_struct *s, void *user_data) { printf("%d", s->element1); }
原文地址:https://www.cnblogs.com/cfox/p/2984377.html