不带后缀的十六进制文字出现“变窄转换”警告?

时间:2019-01-24 11:44:49

标签: c++

static int var[2] __attribute__ ((aligned (8))) =
{
    0x0255cfa8,
    0xfdfcddfc
};

为什么会收到警告:narrowing conversion of '4261207548u' from 'unsigned int' to 'int' inside { } is ill-formed in C++11 [-Wnarrowing]

即使数字没有后缀uU,它们似乎也被视为未签名?

1 个答案:

答案 0 :(得分:1)

如果int是您平台上的32位,则0xfdfcddfcunsigned。那是因为您使用了十六进制表示法。

您有用的编译器会警告您该数字对于int而言太大。

请注意,如果您编写了等效的拒绝对象,那么它将是signed类型(longlong long),并且编译器将发出稍有不同的警告。

参考:https://en.cppreference.com/w/cpp/language/integer_literal#The_type_of_the_literal

相关问题