是“无符号长”为有效在C'无符号长“? [英] Is 'long unsigned' as valid as 'unsigned long' in C?

查看:145
本文介绍了是“无符号长”为有效在C'无符号长“?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个问题最近被问及是否 ULL LLU 有效期为在指定C.无符号很长很长的常量我知道他们俩都是有效的,但我在想, ULL 将是preferable因为它匹配类型无符号长长

A question was recently asked about whether ULL or LLU was valid for specifying unsigned long long constants in C. I know they're both valid but I was thinking that ULL would be preferable since it matched the type unsigned long long.

不过,我现在不那么肯定。在 GCC 编译器允许毫无怨言以下内容:

However, I'm not so certain now. The gcc compiler allowed the following without complaint:

int main(void) {
    unsigned int a = 1;
    int unsigned b = 2;
    return 0;
}

所以我的问题是: INT无符号,而像其他的变化很长很长的无符号,根据有效的类型标准?

So my question is: are int unsigned, and other variations like long long unsigned, valid types according to the standard?

推荐答案

在ISO C11标准规定在 6.2.5类型

The ISO C11 standard states in 6.2.5 Types:

有五个标准符号整数类型,指定为符号的字符,短整型,整型,长整型,长长整型。

There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int.

有关每个符号整数类型的,有一个相应的(但不同)的无符号整数型(与关键字指定的无符号的),使用相同的存储量(包括符号信息),并具有同样的对齐要求。

For each of the signed integer types, there is a corresponding (but different) unsigned integer type (designated with the keyword unsigned) that uses the same amount of storage (including sign information) and has the same alignment requirements.

但有在该节没有规定的任务给的为了的其中的基本类型和无符号出现修改。

However there's no mandate in that section as to the order in which the base type and unsigned modifier appears.

另外,控制部就是后来的标准, 6.7.2类型说明符,在这里转述:

The controlling section is later in the standard, 6.7.2 Type specifiers, paraphrased here:

类型说明无效字符 INT 浮动签署无符号 _Bool _Complex <结构-或工会说明符> <枚举符> <的typedef名称>

Type specifiers are void, char, short, int, long, float, double, signed, unsigned, _Bool, _Complex, <struct-or-union-specifier>, <enum-specifier>, and <typedef-name>.

至少有一个类型说明符应在每个声明的声明说明符给出,并在每一个结构声明和类型名称说明符限定符列表。类型说明符的每个列表应为以下多集之一(以逗号分隔,当有每个项目一个以上的多集);以任意顺序可能发生的类型说明符,可能混合与其他声明说明符。

At least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each struct declaration and type name. Each list of type specifiers shall be one of the following multisets (delimited by commas, when there is more than one multiset per item); the type specifiers may occur in any order, possibly intermixed with the other declaration specifiers.

据然后继续列出所有的多集,如 unsigned long类型或unsigned long int类型

It then goes on to list all the multisets, such as unsigned long, or unsigned long int.

但重要的短语有的类型说明符以任意顺序可能发生,意思就是所有的这些都是有效的多集:

But the important phrase there is the type specifiers may occur in any order, meaning that all of these are valid for that multiset:

unsigned long
long unsigned

unsigned long int
unsigned int long
long unsigned int
long int unsigned
int unsigned long
int long unsigned

这篇关于是“无符号长”为有效在C'无符号长“?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆