[英]Is type of unsigned short + int implementation-defined?
Given this code, 有了这段代码,
unsigned short us = 0;
int i = 0;
auto sum = us + i;
is the type of sum
implementation-defined? 实现的
sum
类型是定义的吗? My reading of the C++11 standard says yes: 我对C ++ 11标准的阅读是:
sum
is int. sum
为int。 sum
is unsigned int. sum
的类型为unsigned int。 If the above analysis is legitimate, it means that using auto
to declare variables initialized with arithmetic expressions on built-in types can lead to implementation-defined results. 如果以上分析是合理的,则意味着使用
auto
声明对内置类型使用算术表达式初始化的变量可能会导致实现定义的结果。 I'm guessing it would surprise a lot of programmers that the type of sum
above is not fully determined by the standard. 我猜想这会让很多程序员感到惊讶,上述
sum
的类型不是完全由标准确定的。
Is my reasoning legitimate? 我的推理合法吗?
The type is implementation-specific, but not implementation-defined. 类型是特定于实现的,但不是实现定义的。 Implementation-defined means that the implementation must document what it does.
实施定义的意思是实施必须记录其功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.