O'Reilly logo

The Go Programming Language Phrasebook by David Chisnall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required