简体   繁体   English

unsigned short int和unsigned short之间的区别

[英]difference between unsigned short int and unsigned short

Is there a difference between unsigned short int and a unsigned short decleration in c and if so, what is it please ? unsigned short int和c中的unsigned short decleration之间是否存在差异?如果是,请问它是什么? I tried looking online, but couldn't find anything worthwhile. 我尝试在线查找,但找不到任何有价值的东西。

unsigned short int x1;
unsigned short x2;

Lastly, if there is a difference, how can I cast them to each other respectively please? 最后,如果有差异,我怎么能分别把它们互相投射?

From C11 [PDF] (irrelevant parts omitted) (emphasis mine): C11 [PDF] (无关的部分省略)(强调我的):

6.7.2.2: 6.7.2.2:

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. 类型说明符可以按任何顺序出现,可能与其他声明说明符混合。

  • ... ...
  • short , signed short , short int , or signed short int shortsigned shortshort intsigned short int
  • unsigned short , or unsigned short int unsigned shortunsigned short int
  • ... ...

6.7.2.5: 6.7.2.5:

Each of the comma-separated multisets designates the same type ... 每个以逗号分隔的多个集合都指定相同的类型 ......

Just using short is a short-hand (no pun intended) way of writing short int . 只是使用short是一种写short int脚的短手(没有双关语)。 Just a long is a short-hand for long int . 就在long是短手long int

No difference in the both. 两者没有区别。

The second is considered to be an int and are simply omitted. 第二个被认为是一个int,只是省略了。

They are synonyms. 他们是同义词。 If you're compiler does something different with them, it's broken. 如果你的编译器做了与它们不同的事情,它就会被打破。

There is no difference. 没有区别。 Try the sizeof operator: 试试sizeof运算符:

main()
{
  unsigned short int x1;
  unsigned short x2;

  printf("%d/%d\n", sizeof x1, sizeof x2);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM