[SDL] Portable float packing/unpacking.
skaller
skaller at users.sourceforge.net
Mon Feb 13 21:44:45 PST 2006
On Mon, 2006-02-13 at 20:58 +0000, mal content wrote:
> On 2/13/06, Bob Pendleton <bob at pendleton.com> wrote:
> > By definition uint32 and float32 are the safe size. That is the reasons
> > for the 32 following the uint and float parts :-). These types are not
> > built in to C/C++ they are typedef'ed somewhere in the code an hopefully
> > a test was included to make sure that sizeof(uint32) == 4 and
>
> Yes, generated with this:
>
> #include <stdio.h>
>
> int go(const char* s)
> {
In that case, you can try to check the alignment of both is the same!
Alignment can be tested by the trick, where T is the type
you're finding the alignment of:
struct X { unsigned char dummy; T x; };
printf("%d",(int)offsetof(X,x));
with appropriate header files and mainline. This trick assumes
that x is properly aligned without the compiler introducing
any gratuitous padding.
Just one comment -- the choice of the name 'uint32' is not so good,
because it is so obvious, and may clash with someone elses
definition of that name (almost certainly for the same purpose).
Most people use a prefix to try to reduce this possibility, eg:
SDL_uint32 // SDL
MYAPP_uint32 // MYAPP
Pretty messy. C99 provides
uint32_t
optionally in inttypes.h
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
More information about the SDL
mailing list