我希望能够编写 int32
而不是 int
和 uint64
而不是 unsigned __int64
。我可以使用 typedef
创建一个名为 PrimitiveTypes.h
的文件来完成此操作。
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned int uint;
typedef __int64 int64;
typedef unsigned __int64 uint64;
现在我可以在每个需要使用基元的文件中包含 PrimitiveTypes.h
,事实证明这与每个文件都非常接近。
也许这是不好的做法,但有没有办法在全局范围内添加重新定义,这样我就不必在每个文件中手动包含新基元,或者可能是问题的另一种解决方案?我正在使用 Visual Studio,以防有任何特定的解决方案。
最佳答案
在标准 C++ 中,我们有 <cstdint>
这个标题。
就说
#include <cstdint>
对于您通常可以依赖的旧标准
#include <stdint.h>
是的,您必须在使用这些类型的每个文件中包含它。不过,您可能有一个项目中央头文件,无论如何它都包含在所有地方。
关于c++ - 全局重命名原始数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23649626/