Sign in to follow this  
ICUP

SDL Portability and Data Types

Recommended Posts

I usually only use primitive data types in my programs. I think I've read in various places thought that not all primitives are the same on every system. To make my programs more portable, what data types should I be using? I've seen those Uint32, Uint16, etc. types before. Should I be using these if I'm concerned about portability? Also, which ones do SDL provide and where are they defined?

Share this post


Link to post
Share on other sites
The fixed sized integers are defined in SDL_stdinc.h. If you include SDL.h you don't have to include SDL_stdinc.h.
The types are Sint8, Uint8, Sint16, Uint16, Sint32, Uint32, Sint64 and Uint64.
Types starting with S are signed integers and U is unsigned integers.

To be portable you don't have to use fixed sized integers everywhere. Use them when you want to be sure about the size. If a SDL function returns one of these types I think it's best to use that type to store the result.

Share this post


Link to post
Share on other sites
It should only be a concern when you are dealing with I/O*. Inside your own program logic you probably won't need fixed size data types. If you plan on making your code work on esoteric architectures you might need to be a bit more careful, for example it is far easier to overflow int if it is only 16 bits rather than the more usual 32. Certainly be careful when deciding to use unsigned types, they can be tricksy - particularly if you mix them with signed types. Ensure your compiler warning level is high enough to emit warnings about signed/unsigned comparisons for example.

The data types SDL provides are included via the SDL.h header, I found a list of them [url="http://www.libsdl.org/tmp/SDL-1.3-docs/SDL__stdinc_8h.html"]here[/url]. The "stdint.h" or <cstdint> also provides fixed size types, if it is available.

* Unfortunately "I/O" is a big topic, it covers keyboard/mouse input, display output, audio, loading from files, saving files, touching the network, almost anything that isn't pure computation. If you split your program based on something like the MVC pattern then the model should be free of I/O and therefore reasonably safe from requiring fixed size data types.

Share this post


Link to post
Share on other sites

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