在C++中重新定义基本类型
Redefine basic types in C++
是否可以重新定义C++中的int
?
原因是因为我想在计算机上模拟一些Arduino代码,而不更改Arduino代码。例如,要以相同的方式演示溢出,int
需要是 16 位而不是我机器上的 32 位。
所以本质上我想:
typedef int16_t int;
以及对Arduino使用的其他数据类型执行相同的操作。
但是我认为这是不可能的,因为它会引发错误(不出所料(:
error: cannot combine with previous 'type-name' declaration specifier
有没有办法让我轻松做到这一点?
您无法重新定义int
但您可以停止根据int
编写代码并使用类型别名,如下所示:
typedef int int_type;
int main()
{
int_type i = 0;
// etc...
}
然后,您可以根据需要切换类型:
typedef int16_t int_type; // now using 16 bit integers
相关文章:
- 使用QJsEngine在Qt中注册自定义类型
- 在UE4中使用未定义类型'UTextBlock'
- 修改"std::set"中用户定义类型的值
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 如何使自定义类型在unordered_map中用作键
- 在 C++20 中是否不再允许在 std 中对程序定义类型的函数模板进行专用化?
- Qt5 远程对象 + 自定义类型,但不在 POD 中
- 为什么转换函数声明不需要至少一个定义类型说明符
- 标准::原子中的自定义类型
- 如何使用自定义类型声明Arduino数组?
- 如何在 Cython 中定义返回 cpp 定义类型的函数?
- 使用自定义访问者时具有自定义类型的提升变体失败(源自 boost::static_visitor)
- 您可以将binary_search应用于具有自定义类型的矢量吗?
- 在自定义类型图中重用 SWIG 映射
- 扩展自定义类型的spdlog
- vim使用户定义类型的COLOR与C++中的基本类型相同
- 重载自定义类型的 std::to_string 和 std::to_chars?
- 具有未声明/未定义类型的 typedef 结构
- 函数重载:内置类型与用户定义类型