C问题包括警卫

时间:2017-03-10 01:58:58

标签: c header include include-guards

我有一个包含防护设置的头文件。我的项目中有多个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:

3 个答案:

答案 0 :(得分:5)

#ifndef __BST_INCLUDED
#define __BST_INCLUDED__
//bunch of code here
#endif

这不会保护任何东西。原因很简单__BST_INCLUDED____BST_INCLUDED不同,__BST_INCLUDED永远不会被定义。

但是:

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:

此错误并未告诉您“该函数已包含在其他文件中”,这是一个完全不相关的错误。 “包括来自”部分只是告诉你编译器如何到达它后面显示的行(问题中缺少)。

答案 1 :(得分:0)

你的包括警卫没事。问题是您已为pruneBSTNode函数声明了多个不同的签名。确保标题和.c文件在返回类型和参数类型上达成一致。

答案 2 :(得分:0)

#ifndef FILE_NAME_HPP
#define FILE_NAME_HPP


#endif

不同
if display_results(player, computer) == "Player won!"

此外,在编译标题时,我的建议是你为包含守卫使用更常见的约定

//Add attachment
// $_FILES['inputBriefing'] is an array not the file
// adding the file as an attachment before checking for errors is a bad idea also
//$mail->addAttachment($_FILES['inputBriefing']);
if (isset($_FILES['inputBriefing']) && $_FILES['inputBriefing']['error'] == UPLOAD_ERR_OK) {

    // this is attempting to add an address to send the email to
    //$mail->addAddress($_FILES['inputBriefing']['tmp_name'],$_FILES['inputBriefing']['name']);
    $mail->addAttachment($_FILES['inputBriefing']['tmp_name'],
                           $_FILES['inputBriefing']['name']);
 }
但是,唉,就像其他人说的那样。你的错误不是来自那里。

相关问题