问题描述
在我的项目中,我使用的第三方堆栈包含一个包含 typedef 的头文件。我的项目还包含一个包含相同 typedef 的头文件。我在 Visual Studio 中收到以下警告。
1.警告 C4142“int32_t”:类型的良性重新定义
2.警告 C4142“uint32_t”:类型的良性重新定义
third_party_stack.h 包含
typedef signed long int32_t; /* Signed 32 bit data */
typedef unsigned long uint32_t; /* Unsigned 32 bit data */
我的项目包括 stdint.h,其中包含此
typedef int int32_t;
typedef unsigned int uint32_t;
在我的项目中,我按此顺序包含标题
My_project.h
third_party_stack.h
我应该怎么做才能摆脱警告(我使用的是 C 语言)。谢谢。
解决方法
要么禁用警告,要么稍微讨厌。
#include "My_project.h"
#define int32_t thirdparty_int32_t
#define uint32_t thirdparty_uint32_t
#include "third_party_stack.h"
#undef int32_t
#undef uint32_t
或者简单地修改第 3 方标头以包含 cstdint,并删除它们的 typedef。然后将该更改作为 PR 推回给他们 ;)