【发布时间】:2017-07-31 05:37:41
【问题描述】:
我有一个包含保护设置的头文件。我的项目中有多个需要此头文件进行编译的 C 文件。但是,当我去编译时,我收到一条错误消息,指出该函数已包含在另一个文件中。包含警卫不应该防止这种情况发生吗?理论上我相信我应该能够多次导入这个文件而不会出现这个问题。
#ifndef __BST_INCLUDED
#define __BST_INCLUDED__
//bunch of code here
#endif
错误:
bst.h:22:13: error: conflicting types for ‘pruneBSTNode’
extern void pruneBSTNode(bst *tree,bstNode *node);
^
In file included from vbst.h:5:0,
from bstrees.c:7:
【问题讨论】:
-
或许用
#pragma once -
关于 __BST_INCLUDED,害怕双下划线! Double underscore is reserved for use by the library implementation 如果你这样做并与某些库标识符发生冲突,可能会发生糟糕且非常怪异,难以调试的事情,所以不要这样做。
-
@user4581301:文件范围内的单个下划线也是如此。
标签: c header include include-guards