Sign in to follow this  

making code that is amd64 and x86 safe

This topic is 4690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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."

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 4690 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this