You are previewing The Go Programming Language Phrasebook.

The Go Programming Language Phrasebook

Cover of The Go Programming Language Phrasebook by David Chisnall Published by Addison-Wesley Professional

3. Numbers

When I first learned C, the compiler supported 16-bit ints and 32-bit longs. A few years later, it became more common for int to be 32 bits. A lot of code was written with assumptions about the sizes of C types, and this caused people a lot of problems when 64-bit systems became common.

The C99 standard introduced the stdint.h header, which defined types like uint32_t, an unsigned integer that was 32 bits on any platform. This helped a bit, but on some platforms a cast between a uint32_t and an unsigned int was safe and wouldn’t generate a warning, since they were the same underlying type, while on others it was not.

Go learned from this mess and provides explicitly sized integer and floating-point types from the start. A uint64 is ...

The best content for your career. Discover unlimited learning on demand for around $1/day.