Greg, On 3 May 2012 10:02, Greg Keogh <[email protected]> wrote: > Folks, I’m just copying some old C code (no joking!) from 15 years ago > over to C# and for the life of me I’ve forgotten how to convert the integer > types. Am I right in this guess? > > C int = C# short (Int16) > C long = C# int (Int32)
The short answer: no. You can only know by looking it up in the documentation for your C compiler. The long answer: The width of integer types in C is implementation-defined, but must be at least wide enough to cover the ranges specified in section 5.2.4.2.1 of the C standard (see limits.h): char: large enough to represent -127 to 127 short: large enough to represent -32767 to 32767 int: large enough to represent -32767 to 32767 long: large enough to represent -2147483647 to 2147483647 (these numbers are for C99) A C int is *at least* 16-bits but could be wider. Almost every 32-bit compiler uses ints 32-bits wide. A C long is *at least* 32-bits but could be wider. Almost every 32-bit compiler uses 64-bit longs. There appear to be no such conventions for 64-bit compilers since different OSes managed the transition to 64-bit differently. -- Thomas
