我需要为客户端提供一个C静态库,并且需要能够使结构定义不可用.最重要的是,我需要能够使用全局变量在库初始化之前执行代码.
这是我的代码:
private.h
#ifndef PRIVATE_H
#define PRIVATE_H
typedef struct TEST test;
#endif
private.c (this should end up in a static library)
#include "private.h"
#include <stdio.h>
struct TEST
{
TEST()
{
printf("Execute before main and have to be unavailable to the user.\n");
}
int a; // Can be modified by the user
int b; // Can be modified by the user
int c; // Can be modified by the user
} TEST;
main.c
test t;
int main( void )
{
t.a …Run Code Online (Sandbox Code Playgroud)