Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between an unsigned short and a USHORT?

Tags:

c++

variables

What is the difference between USHORT and an unsigned short and when would you use each?

like image 805
Stas Jaro Avatar asked Dec 22 '22 05:12

Stas Jaro


2 Answers

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.

Use unsigned short and your code will be portable - don't use USHORT unless you company's coding standard requires it.

like image 95
Adrian Cornish Avatar answered Dec 24 '22 01:12

Adrian Cornish


unsigned short is a standard C++ expression and USHORT is not. The precise definition can be found in the Wikipedia article Integer (computer science).

Sometimes, we typedef unsigned short USHORT in the header. Then USHORT can be used as well as unsigned short.

like image 32
tyger Avatar answered Dec 24 '22 02:12

tyger