pa_endianness.h

Go to the documentation of this file.
00001 #ifndef PA_ENDIANNESS_H
00002 #define PA_ENDIANNESS_H
00003 /*
00004  * $Id: pa_endianness.h 1083 2006-08-23 07:30:49Z rossb $
00005  * Portable Audio I/O Library current platform endianness macros
00006  *
00007  * Based on the Open Source API proposed by Ross Bencina
00008  * Copyright (c) 1999-2002 Phil Burk, Ross Bencina
00009  *
00010  * Permission is hereby granted, free of charge, to any person obtaining
00011  * a copy of this software and associated documentation files
00012  * (the "Software"), to deal in the Software without restriction,
00013  * including without limitation the rights to use, copy, modify, merge,
00014  * publish, distribute, sublicense, and/or sell copies of the Software,
00015  * and to permit persons to whom the Software is furnished to do so,
00016  * subject to the following conditions:
00017  *
00018  * The above copyright notice and this permission notice shall be
00019  * included in all copies or substantial portions of the Software.
00020  *
00021  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00022  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00023  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00024  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
00025  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00026  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00027  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00028  */
00029 
00030 /*
00031  * The text above constitutes the entire PortAudio license; however, 
00032  * the PortAudio community also makes the following non-binding requests:
00033  *
00034  * Any person wishing to distribute modifications to the Software is
00035  * requested to send the modifications to the original developer so that
00036  * they can be incorporated into the canonical version. It is also 
00037  * requested that these non-binding requests be included along with the 
00038  * license above.
00039  */
00040 
00059 #ifdef __cplusplus
00060 extern "C"
00061 {
00062 #endif /* __cplusplus */
00063 
00064 /* If this is an apple, we need to do detect endianness this way */
00065 #if defined(__APPLE__)
00066     /* we need to do some endian detection that is sensitive to harware arch */
00067     #if defined(__LITTLE_ENDIAN__)
00068        #if !defined( PA_LITTLE_ENDIAN )
00069           #define PA_LITTLE_ENDIAN
00070        #endif
00071        #if defined( PA_BIG_ENDIAN )
00072           #undef PA_BIG_ENDIAN
00073        #endif
00074     #else
00075        #if !defined( PA_BIG_ENDIAN )
00076           #define PA_BIG_ENDIAN
00077        #endif
00078        #if defined( PA_LITTLE_ENDIAN )
00079           #undef PA_LITTLE_ENDIAN
00080        #endif
00081     #endif
00082 #else
00083    /* this is not an apple, so first check the existing defines, and, failing that,
00084       detect well-known architechtures. */
00085 
00086    #if defined(PA_LITTLE_ENDIAN) || defined(PA_BIG_ENDIAN)
00087        /* endianness define has been set externally, such as by autoconf */
00088 
00089        #if defined(PA_LITTLE_ENDIAN) && defined(PA_BIG_ENDIAN)
00090        #error both PA_LITTLE_ENDIAN and PA_BIG_ENDIAN have been defined externally to pa_endianness.h - only one endianness at a time please
00091        #endif
00092 
00093    #endif
00094    /* endianness define has not been set externally */
00095 
00096    /* set PA_LITTLE_ENDIAN or PA_BIG_ENDIAN by testing well known platform specific defines */
00097 
00098    #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(LITTLE_ENDIAN) || defined(__i386) || defined(_M_IX86)
00099       #define PA_LITTLE_ENDIAN /* win32, assume intel byte order */
00100    #else
00101       #define PA_BIG_ENDIAN
00102    #endif
00103 
00104    #if !defined(PA_LITTLE_ENDIAN) && !defined(PA_BIG_ENDIAN)
00105    /*
00106     If the following error is raised, you either need to modify the code above
00107     to automatically determine the endianness from other symbols defined on your
00108     platform, or define either PA_LITTLE_ENDIAN or PA_BIG_ENDIAN externally.
00109    */
00110    #error pa_endianness.h was unable to automatically determine the endianness of the target platform
00111    #endif
00112 
00113 #endif
00114 
00115 /* PA_VALIDATE_ENDIANNESS compares the compile time and runtime endianness,
00116  and raises an assertion if they don't match. <assert.h> must be included in
00117  the context in which this macro is used.
00118 */
00119 #if defined(PA_LITTLE_ENDIAN)
00120     #define PA_VALIDATE_ENDIANNESS \
00121     { \
00122         const long nativeOne = 1; \
00123         assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 1 ); \
00124     }
00125 #elif defined(PA_BIG_ENDIAN)
00126     #define PA_VALIDATE_ENDIANNESS \
00127     { \
00128         const long nativeOne = 1; \
00129         assert( "PortAudio: compile time and runtime endianness don't match" && (((char *)&nativeOne)[0]) == 0 ); \
00130     }
00131 #endif
00132 
00133 
00134 #ifdef __cplusplus
00135 }
00136 #endif /* __cplusplus */
00137 #endif /* PA_ENDIANNESS_H */

Generated on Fri Aug 25 17:18:23 2006 for PortAudio by  doxygen 1.4.7