C++ unsigned short 和 USHORT 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8453788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between an unsigned short and a USHORT?
提问by Stas Jaro
What is the difference between USHORT
and an unsigned short
and when would you use each?
USHORT
和 an之间有什么区别,unsigned short
您何时会使用它们?
回答by Adrian Cornish
USHORT is a macro which is not part of the official C++ language (it's probably defined or typedef'ed somewhere). unsigned short is an official type defined by the C++ language as an integer that can at least hold numbers between 0 and 65535.
USHORT 是一个宏,它不是官方 C++ 语言的一部分(它可能在某处定义或类型化)。unsigned short 是 C++ 语言定义的一种官方类型,它是一个整数,它至少可以容纳 0 到 65535 之间的数字。
Use unsigned short and your code will be portable - don't use USHORT unless you company's coding standard requires it.
使用 unsigned short 并且您的代码将是可移植的 - 除非您公司的编码标准要求,否则不要使用 USHORT。
回答by tyger
unsigned short
is a standard C++expression and USHORT is not. The precise definition can be found in the Wikipedia article Integer (computer science).
unsigned short
是标准的C++表达式,而 USHORT 不是。精确的定义可以在维基百科文章整数(计算机科学)中找到。
Sometimes, we typedef unsigned short USHORT in the header. Then USHORT can be used as well as unsigned short.
有时,我们在标题中键入def unsigned short USHORT。然后可以使用 USHORT 以及 unsigned short。