Game Development Reference
In-Depth Information
Chapter 26
Supporting Multiple Platforms
in C++
There will come a time in your game development career when you have to write code that will only
work on a single platform. That code will have to be compiled out of other platforms. You will more
than likely also have to find alternative implementations for each of the platforms you will be working
on. Classic examples of such code can usually be found in interactions between your game and
online login and microtransaction solutions such as Game Center, Google+, Xbox Live, PlayStation
Network, and Steam.
There can be more complicated problems between different platforms. iOS devices run on Arm
processors; Android supports Arm, x86, and MIPS; and most other operating systems can be run
on more than a single instruction set. The problem that can arise is that compilers for each of these
CPU instruction sets can use different sizes for their built-in types. This is especially true when
moving from 32-bit CPUs to 64-bit CPUs. In these situations pointers are no longer 32 bits in size;
they are, in fact, 64 bits. This can cause all sorts of portability problems if you assume that types and
pointers are of a fixed size. These issues can be very difficult to track down and will usually cause
either graphical corruption or you will see your programs simply crash at random times.
Ensuring Types Are the Same Size on Multiple Platforms
Ensuring that your program uses the same size of types in your programs on multiple platforms will
be easier than you might initially think. The C++ STL provides a header called cstdint that contains
types that are of a consistent size. These types are:
int8_t and uint8_t
int16_t and uint16_t
int32_t and uint32_t
int64_t and uint64_t
277
 
Search WWH ::




Custom Search