【发布时间】:2010-05-24 07:10:03
【问题描述】:
我需要向客户端提供一个 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 = 0;
t.b = 0;
t.c = 0;
return 0;
}
显然这段代码不起作用...但显示我需要做什么...有人知道如何使这个工作吗?我google了很多,但找不到答案,任何帮助将不胜感激。
TIA!
【问题讨论】:
标签: c static struct static-libraries