making code that is amd64 and x86 safe

Started by
2 comments, last by kRogue 19 years, 2 months ago
Hi all, I'd like to make some code which can compile with no issues both with x86 (32-bit) and amd64(64-bit) code generation, under g++/gcc. Now what I have learned is that: in 32bits, pointers, ints, float and longs are 4 bytes doubles are 8 bytes in 64bits, pointers and longs are 64 bits and ints are 32bits what other issue are there? are floats still 4 byte in 64-bits (I am pretty sure it should be, but you never know) and are doubles still 8 bytes? also, if one compiles using openGL's standard header files, eg <Gl/gl.h>, ect that are on the _user's_ systems do the openGL types change sizes? this might be an issue with some openGL calls if the types do change sizes..... now if I stick to say using GLint, GLshort, GLbyte, GLfloat, would I be safe? the main worry I have is reading in binary data files.... I don't even want to think about porting to Mac's easily (due to Big vs Little Endian issues) wit repsect to reading binary data files... though I imagine that floats and doubles should not change.. or do they? I know ints, longs have a different byte order on Mac's.... and to make life as best as possible I do not have access to an amd64 machine Best Regards
Close this Gamedev account, I have outgrown Gamedev.
Advertisement
The safest way to have architecture-portable code is to use the types defined in stdint.h (c99 standard header file) in places where you need to be sure of the type size. As long as the language keeps to IEEE standards, the sizes of float and double are fixed, but at least Java doesn't honour this.

The size of GL types is specified as a minimum of bits, but according to the specs, "[c]orrect interpretation of integer values outside the minimum range is not required, however."
Also keep in mind that the int/long sizes you mention are not carved in stone. 64-bit compilers for Windows use a 32-bit long.
-Mike
Hi,

thanks for the poitner to stdint.h (I should haev realized this!) however, anyone know what the dfference between the "fast" and "least" types in it? for my system it looks like they are the same, but for others?
Close this Gamedev account, I have outgrown Gamedev.

This topic is closed to new replies.

Advertisement