Difference between revisions of "Coding Conventions"

Jump to navigation Jump to search
m
→‎Endianness issues: endianess > endianness
m (We now use C++11 everywhere)
m (→‎Endianness issues: endianess > endianness)
 
Line 17: Line 17:
We are reviewing these decisions from time to time, but so far, in our estimation the drawbacks of using any of these outweigh the hypothetical advantages.
We are reviewing these decisions from time to time, but so far, in our estimation the drawbacks of using any of these outweigh the hypothetical advantages.


== Endianess issues ==
== Endianness issues ==
If you don't know what "Endianess issues" refers to, read up here: http://en.wikipedia.org/wiki/Endianess
If you don't know what "Endianness issues" refers to, read up here: https://en.wikipedia.org/wiki/Endianness


ScummVM engine authors have to keep endianess issues in mind for two reasons:
ScummVM engine authors have to keep endianness issues in mind for two reasons:
* ScummVM runs on both little endian (Windows, x86 Mac OS X, x86 Linux...) and big endian hosts (PowerPC Mac OS X, PlayStation 3 Linux...). So when writing data (think savegames) to files and reading it back again, you need to compensate for this. This is easily done by using the READ_ and WRITE_ macros from common/endian.h (like READ_LE_UINT32 or WRITE_BE_UINT16.) respectively the corresponding Stream class methods (like readUint32LE or writeUint16BE).
* ScummVM runs on both little endian (Windows, x86 Mac OS X, x86 Linux...) and big endian hosts (PowerPC Mac OS X, PlayStation 3 Linux...). So when writing data (think savegames) to files and reading it back again, you need to compensate for this. This is easily done by using the READ_ and WRITE_ macros from common/endian.h (like READ_LE_UINT32 or WRITE_BE_UINT16.) respectively the corresponding Stream class methods (like readUint32LE or writeUint16BE).
* Furthermore, some games existed in multiple versions, e.g. one for Windows and one for Mac OS. In that case, you may have to detect and distinguish these versions and employ different reading calls, to compensate for endian differences in the game data files.
* Furthermore, some games existed in multiple versions, e.g. one for Windows and one for Mac OS. In that case, you may have to detect and distinguish these versions and employ different reading calls, to compensate for endian differences in the game data files.


As most desktop machines are now little-endian i.e. x86, debugging any remaining endian issues without access to a big-endian desktop system is hard. [[HOWTO-Debug-Endian-Issues |HOWTO Debug Endian Issues]] details a solution to this by using a virtual machine software package to emulate a machine with a different endian CPU to the host system.
As most desktop machines are now little-endian i.e. x86, debugging any remaining endian issues without access to a big-endian desktop system is hard. [[HOWTO-Debug-Endian-Issues|HOWTO Debug Endian Issues]] details a solution to this by using a virtual machine software package to emulate a machine with a different endian CPU to the host system.


== Struct packing ==
== Struct packing ==
149

edits

Navigation menu