本文介绍了显式类型转换(功能符号)和简单类型说明符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

移植一些代码我发现了这一行

  unsigned char uc = unsigned char(c); 

被MSVC接受但被GCC拒绝。这个语法是否正确?

标准说明

这是否意味着MS正确?是 unsigned char 一个'简单类型说明符'?

解决方案

和是正确的,代码无效。



是单字型的名称:

unsigned char 不是简单类型说明符,而是组合 o f简单类型说明符,如
$ b

是来自cppreference.com的一个解释:


Porting some code I have discovered that line

unsigned char uc = unsigned char(c);

is accepted by MSVC but rejected by GCC. Is this syntax correct?
Standard says that

Does it mean that MS is right? Is unsigned char a 'simple-type-specifier'?

解决方案

GCC and CLANG are correct, the code is not valid.

Simple type specifier is single-word type name:

unsigned char is not a simple-type-specifier, it's a combination of simple-type-specifiers, as shown in Table 9 from standard.

Here's an explanation from cppreference.com:

这篇关于显式类型转换(功能符号)和简单类型说明符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 10:39