小编Bob*_*ury的帖子

隐藏静态库中的结构定义

我需要为客户端提供一个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)

c static struct static-libraries

6
推荐指数
1
解决办法
3136
查看次数

标签 统计

c ×1

static ×1

static-libraries ×1

struct ×1