#ifndef __CONFIG_H__
#define __CONFIG_H__
#include <stdio.h>
#define USE_LIST
#endif
#ifndef __NODE_H__
#define __NODE_H__
struct node
{
#ifdef USE_LIST
struct node* prev;
struct node* next;
#endif
int i;
};
#endif
#ifndef __1_H__
#define __1_H__
#include "config.h"
#include "node.h"
void f1()
{
printf("in f1(), sizeof(struct node) = %d\n", sizeof(struct node));
}
#endif
#ifndef __2_H__
#define __2_H__
#include "node.h"
#include "config.h"
void f2()
{
printf("in f2(), sizeof(struct node) = %d\n", sizeof(struct node));
}
#endif
#define USE_1
#ifdef USE_1
#include "1.h"
#else
#include "2.h"
#endif
int main()
{
#ifdef USE_1
f1();
#else
f2();
#endif
return 0;
}
以后再遇到这样的问题,我的做法是把这些预定义的宏集中放在一个文件中,并且放在每个需要该头文件的文件中包含头文件的最开始位置.