[Openal-devel] Format Ambiguities in OAL

Panne Sven BenQ MD PBM IPM TPS 4 sven.panne at siemens.com
Thu Oct 20 03:46:47 PDT 2005


*sigh* Similar problems pop up again and again... :-( I think the world
would be a better place if everybody had read the autoconf documentation,
even if one never intended to use it in a project. Its very central mantra
is: If you need a non-portable feature, test for this feature. Sounds
extremely simple and should be common sense, but it is largely ignored by
lots of code out in the wild...

Regarding our problem at hand: Testing for an OS has obviously nothing to do
with endianess, so we can immediately mark this as "completely wrong". But
even the second way of testing is wrong: IIRC PowerPC can run in
little-endian and big-endian mode. Again, this problem is caused by not
really testing for the needed feature (endianess), but for something
different (processor).

So what to do? If the project is autoconf-based, things are simple: Just use
AC_C_BIGENDIAN. If the project does not use autoconf, have a look at the
autoconf macro what to do. :-) Basically it does the following:

 * Check for some preprocessor #defines related to endianess

 * If that did not give a clue, compile and run a test program.

 * If even that did not give a clue (e.g. because of cross-compilation),
compile some code and look into the object code/data for some clues.

But if having all code variants compiled into the project is not a problem,
I'd simply do a test at runtime. It's very simple and the most bullet-proof
approach, we use it e.g. in the ALUT loaders.

Cheers,
   S.

> -----Original Message-----
> From: openal-devel-admin at opensource.creative.com 
> [mailto:openal-devel-admin at opensource.creative.com] On Behalf 
> Of William Stewart
> Sent: Donnerstag, 20. Oktober 2005 02:36
> To: openal-devel at opensource.creative.com
> Subject: [Openal-devel] Format Ambiguities in OAL
> [...]
> Secondly, we also wanted to raise this to this list, as we 
> can imagine code that might look like this (this is in the 
> context of any utility code, like alut, that is being used to 
> read data from files into the OAL Buffers for OAL to render).
> 
> #if TARGET_OS_MAC
> 	// convert to big endian
> #elif TARGET_OS_WIN
> 	// convert to little endian
> #elif
> 	//....
> #endif
> 
> When really the code needs to be at a lower level of discrimination:
> 
> #if TARGET_CPU_PPC
> 	// convert to big endian
> #elif TARGET_CPU_X86
> 	// convert to little endian
> #elif
> 	...
> #endif
> [...]



More information about the Openal-devel mailing list