gpt4 book ai didi

linux - 抑制 gcc 警告 : "warning: this is the location of the previous definition"

转载 作者:太空狗 更新时间:2023-10-29 11:24:59 24 4
gpt4 key购买 nike

我需要一组围绕标准系统调用(打开、监听等)的包装器。对于这些,我有一些“#define”,如:

#define open(a,b,c) JCL_Open(a,b,c)

但是当我编译头文件和关联的 .c 文件时,我收到以下警告:

/jcl_wrappers.h:114:1: 警告:“打开”重新定义
/jcl_wrappers.h:113:1: 警告:这是之前定义的位置

我怎样才能抑制这些警告?

最佳答案

include guards在你的头文件中。

基本上你需要把这两行放在头文件的开头

#ifndef _yourincludefilename_h_
#define _yourincludefilename_h_

#endif /* _yourincludefilename_h_ */

在你包含文件的最后。

编辑:
rascher 是对的,open 不是宏的好名称,因为它会与库函数冲突。通常使宏全部大写是很好的 C 约定,所以我建议将您的宏更改为

#define OPEN(a,b,c) JCL_Open(a,b,c)

甚至更好

#define XYZ_OPEN(a,b,c) JCL_Open(a,b,c)

其中 XYZ 是特定于您的代码的前缀。

关于linux - 抑制 gcc 警告 : "warning: this is the location of the previous definition",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/766964/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com