6
Header file for POSH, the Portable Open Source Harness project.
8
NOTE: Unlike most header files, this one is designed to be included
9
multiple times, which is why it does not have the @#ifndef/@#define
12
POSH relies on environment specified preprocessor symbols in order
13
to infer as much as possible about the target OS/architecture and
14
the host compiler capabilities.
16
NOTE: POSH is simple and focused. It attempts to provide basic
17
functionality and information, but it does NOT attempt to emulate
18
missing functionality. I am also not willing to make POSH dirty
19
and hackish to support truly ancient and/or outmoded and/or bizarre
20
technologies such as non-ANSI compilers, systems with non-IEEE
21
floating point formats, segmented 16-bit operating systems, etc.
23
Please refer to the accompanying HTML documentation or visit
24
http://www.poshlib.org for more information on how to use POSH.
28
Copyright (c) 2004, Brian Hook
31
Redistribution and use in source and binary forms, with or without
32
modification, are permitted provided that the following conditions are
35
* Redistributions of source code must retain the above copyright
36
notice, this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above
39
copyright notice, this list of conditions and the following
40
disclaimer in the documentation and/or other materials provided
41
with the distribution.
43
* The names of this package'ss contributors contributors may not
44
be used to endorse or promote products derived from this
45
software without specific prior written permission.
48
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62
I've been lax about revision histories, so this starts at, um, 1.3.001.
63
Sorry for any inconveniences.
65
1.3.002 - 8/29/2006 - Removed FORCE_DOXYGEN stuff
66
1.3.001 - 2/23/2006 - Incorporated fix for bug reported by Bill Cary,
67
where I was not detecting Visual Studio
68
compilation on x86-64 systems. Added check for
69
_M_X64 which should fix that.
73
I have yet to find an authoritative reference on preprocessor
74
symbols, but so far this is what I've gleaned:
77
- __GNUC__: GNU C version
78
- __GNUG__: GNU C++ compiler
79
- __sun__ : on Sun platforms
80
- __svr4__: on Solaris and other SysV R4 platforms
81
- __mips__: on MIPS processor platforms
82
- __sparc_v9__: on Sparc 64-bit CPUs
83
- __sparcv9: 64-bit Solaris
84
- __MIPSEL__: mips processor, compiled for little endian
85
- __MIPSEB__: mips processor, compiled for big endian
86
- _R5900: MIPS/Sony/Toshiba R5900 (PS2)
93
- __ECC : compiler version, IA64 only
98
- __i386__ : IA-32 only
100
- __ia64 : IA-64 only
101
- __ia64__ : IA-64 only
104
- __INTEL_COMPILER : IA-32 or IA-64, newer versions only
106
Apple's C/C++ Compiler for OS X:
121
- __i386, __i386, i386
124
- _ADDR64: if 64-bit pointers
128
SGI's CC compiler predefines the following (and more) with -ansi:
135
- anyone know if there is a predefined symbol for the compiler?!
138
- as GnuC but also defines _WIN32, __WIN32, WIN32, _X86_, __i386, __i386__, and several others
146
Microsoft Visual Studio predefines the following:
149
- _M_IX6 (on x86 systems)
150
- _M_X64: on x86-64 systems
151
- _M_ALPHA (on DEC AXP systems)
152
- _SH3: WinCE, Hitachi SH-3
159
- sparc and _sparc (SPARC systems only)
160
- i386 and _i386 (x86 systems only)
161
- __SVR4 (Solaris only)
162
- __sparcv9: 64-bit solaris
164
- _LP64: defined in 64-bit LP64 mode, but only if <sys/types.h> is included
166
Borland C/C++ predefines the following:
169
DEC/Compaq C/C++ on Alpha:
172
- __unix__ (on Tru64 Unix)
175
- __DECCXX (C++ compilation)
180
- __64BIT__ if 64-bit mode
182
- __IBMC__: C compiler version
183
- __IBMCPP__: C++ compiler version
184
- _LONG_LONG: compiler allows long long
188
- __DOS__ : if targeting DOS
189
- __386__ : if 32-bit support
190
- __WIN32__ : if targetin 32-bit Windows
192
HP-UX C/C++ Compiler:
195
- __hppa (on PA-RISC)
196
- __LP64__: if compiled in 64-bit mode
203
- macintosh when compiling for MacOS
204
- __INTEL__ for x86 targets
210
** ----------------------------------------------------------------------------
211
** Include <limits.h> optionally
212
** ----------------------------------------------------------------------------
214
#ifdef POSH_USE_LIMITS_H
219
** ----------------------------------------------------------------------------
220
** Determine compilation environment
221
** ----------------------------------------------------------------------------
223
#if defined __ECC || defined __ICC || defined __INTEL_COMPILER
224
# define POSH_COMPILER_STRING "Intel C/C++"
225
# define POSH_COMPILER_INTEL 1
228
#if ( defined __host_mips || defined __sgi ) && !defined __GNUC__
229
# define POSH_COMPILER_STRING "MIPSpro C/C++"
230
# define POSH_COMPILER_MIPSPRO 1
233
#if defined __hpux && !defined __GNUC__
234
# define POSH_COMPILER_STRING "HP-UX CC"
235
# define POSH_COMPILER_HPCC 1
239
# define POSH_COMPILER_STRING "Gnu GCC"
240
# define POSH_COMPILER_GCC 1
243
#if defined __APPLE_CC__
244
/* we don't define the compiler string here, let it be GNU */
245
# define POSH_COMPILER_APPLECC 1
248
#if defined __IBMC__ || defined __IBMCPP__
249
# define POSH_COMPILER_STRING "IBM C/C++"
250
# define POSH_COMPILER_IBM 1
254
# define POSH_COMPILER_STRING "Microsoft Visual C++"
255
# define POSH_COMPILER_MSVC 1
258
#if defined __SUNPRO_C
259
# define POSH_COMPILER_STRING "Sun Pro"
260
# define POSH_COMPILER_SUN 1
263
#if defined __BORLANDC__
264
# define POSH_COMPILER_STRING "Borland C/C++"
265
# define POSH_COMPILER_BORLAND 1
268
#if defined __MWERKS__
269
# define POSH_COMPILER_STRING "MetroWerks CodeWarrior"
270
# define POSH_COMPILER_METROWERKS 1
273
#if defined __DECC || defined __DECCXX
274
# define POSH_COMPILER_STRING "Compaq/DEC C/C++"
275
# define POSH_COMPILER_DEC 1
278
#if defined __WATCOMC__
279
# define POSH_COMPILER_STRING "Watcom C/C++"
280
# define POSH_COMPILER_WATCOM 1
283
#if !defined POSH_COMPILER_STRING
284
# define POSH_COMPILER_STRING "Unknown compiler"
288
** ----------------------------------------------------------------------------
289
** Determine target operating system
290
** ----------------------------------------------------------------------------
292
#if defined linux || defined __linux__
293
# define POSH_OS_LINUX 1
294
# define POSH_OS_STRING "Linux"
297
#if defined __CYGWIN32__
298
# define POSH_OS_CYGWIN32 1
299
# define POSH_OS_STRING "Cygwin"
303
# define POSH_OS_GAMECUBE
305
# define POSH_OS_STRING "GameCube"
308
#if defined __MINGW32__
309
# define POSH_OS_MINGW 1
310
# define POSH_OS_STRING "MinGW"
313
#if defined GO32 && defined DJGPP && defined __MSDOS__
314
# define POSH_OS_GO32 1
315
# define POSH_OS_STRING "GO32/MS-DOS"
318
/* NOTE: make sure you use /bt=DOS if compiling for 32-bit DOS,
319
otherwise Watcom assumes host=target */
320
#if defined __WATCOMC__ && defined __386__ && defined __DOS__
321
# define POSH_OS_DOS32 1
322
# define POSH_OS_STRING "DOS/32-bit"
326
# define POSH_OS_UNICOS 1
327
# define POSH_OS_STRING "UNICOS"
330
#if ( defined __MWERKS__ && defined __powerc && !defined macintosh ) || defined __APPLE_CC__ || defined macosx
331
# define POSH_OS_OSX 1
332
# define POSH_OS_STRING "MacOS X"
335
#if defined __sun__ || defined sun || defined __sun || defined __solaris__
336
# if defined __SVR4 || defined __svr4__ || defined __solaris__
337
# define POSH_OS_STRING "Solaris"
338
# define POSH_OS_SOLARIS 1
340
# if !defined POSH_OS_STRING
341
# define POSH_OS_STRING "SunOS"
342
# define POSH_OS_SUNOS 1
346
#if defined __sgi__ || defined sgi || defined __sgi
347
# define POSH_OS_IRIX 1
348
# define POSH_OS_STRING "Irix"
351
#if defined __hpux__ || defined __hpux
352
# define POSH_OS_HPUX 1
353
# define POSH_OS_STRING "HP-UX"
357
# define POSH_OS_AIX 1
358
# define POSH_OS_STRING "AIX"
361
#if ( defined __alpha && defined __osf__ )
362
# define POSH_OS_TRU64 1
363
# define POSH_OS_STRING "Tru64"
366
#if defined __BEOS__ || defined __beos__
367
# define POSH_OS_BEOS 1
368
# define POSH_OS_STRING "BeOS"
371
#if defined amiga || defined amigados || defined AMIGA || defined _AMIGA
372
# define POSH_OS_AMIGA 1
373
# define POSH_OS_STRING "Amiga"
377
# define POSH_OS_UNIX 1
378
# if !defined POSH_OS_STRING
379
# define POSH_OS_STRING "Unix-like(generic)"
383
#if defined _WIN32_WCE
384
# define POSH_OS_WINCE 1
385
# define POSH_OS_STRING "Windows CE"
389
# define POSH_OS_XBOX 1
390
# define POSH_OS_STRING "XBOX"
393
#if defined _WIN32 || defined WIN32 || defined __NT__ || defined __WIN32__
394
# define POSH_OS_WIN32 1
395
# if !defined POSH_OS_XBOX
397
# define POSH_OS_WIN64 1
398
# define POSH_OS_STRING "Win64"
400
# if !defined POSH_OS_STRING
401
# define POSH_OS_STRING "Win32"
407
#if defined __palmos__
408
# define POSH_OS_PALM 1
409
# define POSH_OS_STRING "PalmOS"
412
#if defined THINK_C || defined macintosh
413
# define POSH_OS_MACOS 1
414
# define POSH_OS_STRING "MacOS"
418
** -----------------------------------------------------------------------------
419
** Determine target CPU
420
** -----------------------------------------------------------------------------
424
# define POSH_CPU_PPC750 1
425
# define POSH_CPU_STRING "IBM PowerPC 750 (NGC)"
428
#if defined mc68000 || defined m68k || defined __MC68K__ || defined m68000
429
# define POSH_CPU_68K 1
430
# define POSH_CPU_STRING "MC68000"
433
#if defined __PPC__ || defined __POWERPC__ || defined powerpc || defined _POWER || defined __ppc__ || defined __powerpc__
434
# define POSH_CPU_PPC 1
435
# if !defined POSH_CPU_STRING
436
# if defined __powerpc64__
437
# define POSH_CPU_STRING "PowerPC64"
439
# define POSH_CPU_STRING "PowerPC"
444
#if defined _CRAYT3E || defined _CRAYMPP
445
# define POSH_CPU_CRAYT3E 1 /* target processor is a DEC Alpha 21164 used in a Cray T3E*/
446
# define POSH_CPU_STRING "Cray T3E (Alpha 21164)"
449
#if defined CRAY || defined _CRAY && !defined _CRAYT3E
450
# error Non-AXP Cray systems not supported
454
# define POSH_CPU_SH3 1
455
# define POSH_CPU_STRING "Hitachi SH-3"
458
#if defined __sh4__ || defined __SH4__
459
# define POSH_CPU_SH3 1
460
# define POSH_CPU_SH4 1
461
# define POSH_CPU_STRING "Hitachi SH-4"
464
#if defined __sparc__ || defined __sparc
465
# if defined __arch64__ || defined __sparcv9 || defined __sparc_v9__
466
# define POSH_CPU_SPARC64 1
467
# define POSH_CPU_STRING "Sparc/64"
469
# define POSH_CPU_STRING "Sparc/32"
471
# define POSH_CPU_SPARC 1
474
#if defined ARM || defined __arm__ || defined _ARM
475
# define POSH_CPU_STRONGARM 1
476
# define POSH_CPU_STRING "ARM"
479
#if defined mips || defined __mips__ || defined __MIPS__ || defined _MIPS
480
# define POSH_CPU_MIPS 1
482
# define POSH_CPU_STRING "MIPS R5900 (PS2)"
484
# define POSH_CPU_STRING "MIPS"
488
#if defined __ia64 || defined _M_IA64 || defined __ia64__
489
# define POSH_CPU_IA64 1
490
# define POSH_CPU_STRING "IA64"
493
#if defined __X86__ || defined __i386__ || defined i386 || defined _M_IX86 || defined __386__ || defined __x86_64__ || defined _M_X64
494
# define POSH_CPU_X86 1
495
# if defined __x86_64__ || defined _M_X64
496
# define POSH_CPU_X86_64 1
498
# if defined POSH_CPU_X86_64
499
# define POSH_CPU_STRING "AMD x86-64"
501
# define POSH_CPU_STRING "Intel 386+"
505
#if defined __alpha || defined alpha || defined _M_ALPHA || defined __alpha__
506
# define POSH_CPU_AXP 1
507
# define POSH_CPU_STRING "AXP"
510
#if defined __hppa || defined hppa
511
# define POSH_CPU_HPPA 1
512
# define POSH_CPU_STRING "PA-RISC"
515
#if !defined POSH_CPU_STRING
516
# error POSH cannot determine target CPU
517
# define POSH_CPU_STRING "Unknown" /* this is here for Doxygen's benefit */
521
** -----------------------------------------------------------------------------
522
** Attempt to autodetect building for embedded on Sony PS2
523
** -----------------------------------------------------------------------------
525
#if !defined POSH_OS_STRING
526
# define POSH_OS_EMBEDDED 1
528
# define POSH_OS_STRING "Sony PS2(embedded)"
530
# define POSH_OS_STRING "Embedded/Unknown"
535
** ---------------------------------------------------------------------------
536
** Handle cdecl, stdcall, fastcall, etc.
537
** ---------------------------------------------------------------------------
539
#if defined POSH_CPU_X86 && !defined POSH_CPU_X86_64
540
# if defined __GNUC__
541
# define POSH_CDECL __attribute__((cdecl))
542
# define POSH_STDCALL __attribute__((stdcall))
543
# define POSH_FASTCALL __attribute__((fastcall))
544
# elif ( defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__ || defined __MWERKS__ )
545
# define POSH_CDECL __cdecl
546
# define POSH_STDCALL __stdcall
547
# define POSH_FASTCALL __fastcall
551
# define POSH_STDCALL
552
# define POSH_FASTCALL
556
** ---------------------------------------------------------------------------
557
** Define POSH_IMPORTEXPORT signature based on POSH_DLL and POSH_BUILDING_LIB
558
** ---------------------------------------------------------------------------
562
** We undefine this so that multiple inclusions will work
564
#if defined POSH_IMPORTEXPORT
565
# undef POSH_IMPORTEXPORT
569
# if defined POSH_OS_WIN32
570
# if defined _MSC_VER
571
# if ( _MSC_VER >= 800 )
572
# if defined POSH_BUILDING_LIB
573
# define POSH_IMPORTEXPORT __declspec( dllexport )
575
# define POSH_IMPORTEXPORT __declspec( dllimport )
578
# if defined POSH_BUILDING_LIB
579
# define POSH_IMPORTEXPORT __export
581
# define POSH_IMPORTEXPORT
584
# endif /* defined _MSC_VER */
585
# if defined __BORLANDC__
586
# if ( __BORLANDC__ >= 0x500 )
587
# if defined POSH_BUILDING_LIB
588
# define POSH_IMPORTEXPORT __declspec( dllexport )
590
# define POSH_IMPORTEXPORT __declspec( dllimport )
593
# if defined POSH_BUILDING_LIB
594
# define POSH_IMPORTEXPORT __export
596
# define POSH_IMPORTEXPORT
599
# endif /* defined __BORLANDC__ */
600
/* for all other compilers, we're just making a blanket assumption */
601
# if defined __GNUC__ || defined __WATCOMC__ || defined __MWERKS__
602
# if defined POSH_BUILDING_LIB
603
# define POSH_IMPORTEXPORT __declspec( dllexport )
605
# define POSH_IMPORTEXPORT __declspec( dllimport )
607
# endif /* all other compilers */
608
# if !defined POSH_IMPORTEXPORT
609
# error Building DLLs not supported on this compiler (poshlib@poshlib.org if you know how)
611
# endif /* defined POSH_OS_WIN32 */
614
/* On pretty much everything else, we can thankfully just ignore this */
615
#if !defined POSH_IMPORTEXPORT
616
# define POSH_IMPORTEXPORT
620
** ----------------------------------------------------------------------------
621
** (Re)define POSH_PUBLIC_API export signature
622
** ----------------------------------------------------------------------------
624
#ifdef POSH_PUBLIC_API
625
# undef POSH_PUBLIC_API
628
#if ( ( defined _MSC_VER ) && ( _MSC_VER < 800 ) ) || ( defined __BORLANDC__ && ( __BORLANDC__ < 0x500 ) )
629
# define POSH_PUBLIC_API(rtype) extern rtype POSH_IMPORTEXPORT
631
# define POSH_PUBLIC_API(rtype) extern POSH_IMPORTEXPORT rtype
635
** ----------------------------------------------------------------------------
636
** Try to infer endianess. Basically we just go through the CPUs we know are
637
** little endian, and assume anything that isn't one of those is big endian.
638
** As a sanity check, we also do this with operating systems we know are
639
** little endian, such as Windows. Some processors are bi-endian, such as
640
** the MIPS series, so we have to be careful about those.
641
** ----------------------------------------------------------------------------
643
#if defined POSH_CPU_X86 || defined POSH_CPU_AXP || defined POSH_CPU_STRONGARM || defined POSH_OS_WIN32 || defined POSH_OS_WINCE || defined __MIPSEL__
644
# define POSH_ENDIAN_STRING "little"
645
# define POSH_LITTLE_ENDIAN 1
647
# define POSH_ENDIAN_STRING "big"
648
# define POSH_BIG_ENDIAN 1
652
** ----------------------------------------------------------------------------
653
** Cross-platform compile time assertion macro
654
** ----------------------------------------------------------------------------
656
#define POSH_COMPILE_TIME_ASSERT(name, x) typedef int _POSH_dummy_ ## name[(x) ? 1 : -1 ]
659
** ----------------------------------------------------------------------------
662
** We don't require 64-bit support, nor do we emulate its functionality, we
663
** simply export it if it's available. Since we can't count on <limits.h>
664
** for 64-bit support, we ignore the POSH_USE_LIMITS_H directive.
665
** ----------------------------------------------------------------------------
667
#if defined ( __LP64__ ) || defined ( __powerpc64__ ) || defined POSH_CPU_SPARC64
668
# define POSH_64BIT_INTEGER 1
669
typedef long posh_i64_t;
670
typedef unsigned long posh_u64_t;
671
# define POSH_I64( x ) ((posh_i64_t)x)
672
# define POSH_U64( x ) ((posh_u64_t)x)
673
# define POSH_I64_PRINTF_PREFIX "l"
674
#elif defined _MSC_VER || defined __BORLANDC__ || defined __WATCOMC__ || ( defined __alpha && defined __DECC )
675
# define POSH_64BIT_INTEGER 1
676
typedef __int64 posh_i64_t;
677
typedef unsigned __int64 posh_u64_t;
678
# define POSH_I64( x ) ((posh_i64_t)x)
679
# define POSH_U64( x ) ((posh_u64_t)x)
680
# define POSH_I64_PRINTF_PREFIX "I64"
681
#elif defined __GNUC__ || defined __MWERKS__ || defined __SUNPRO_C || defined __SUNPRO_CC || defined __APPLE_CC__ || defined POSH_OS_IRIX || defined _LONG_LONG || defined _CRAYC
682
# define POSH_64BIT_INTEGER 1
683
typedef long long posh_i64_t;
684
typedef unsigned long long posh_u64_t;
685
# define POSH_U64( x ) ((posh_u64_t)(x##LL))
686
# define POSH_I64( x ) ((posh_i64_t)(x##LL))
687
# define POSH_I64_PRINTF_PREFIX "ll"
694
#undef POSH_I64_PRINTF_PREFIX
695
#define POSH_I64( x ) ((posh_i64_t)x)
696
#define POSH_U64( x ) ((posh_u64_t)x)
697
#define POSH_I64_PRINTF_PREFIX "I64"
700
/** Minimum value for a 64-bit signed integer */
701
#define POSH_I64_MIN POSH_I64(0x8000000000000000)
702
/** Maximum value for a 64-bit signed integer */
703
#define POSH_I64_MAX POSH_I64(0x7FFFFFFFFFFFFFFF)
704
/** Minimum value for a 64-bit unsigned integer */
705
#define POSH_U64_MIN POSH_U64(0)
706
/** Maximum value for a 64-bit unsigned integer */
707
#define POSH_U64_MAX POSH_U64(0xFFFFFFFFFFFFFFFF)
709
/* ----------------------------------------------------------------------------
712
** These types are expected to be EXACTLY sized so you can use them for
714
** ----------------------------------------------------------------------------
719
typedef int posh_bool_t;
720
typedef unsigned char posh_byte_t;
722
/* NOTE: These assume that CHAR_BIT is 8!! */
723
typedef unsigned char posh_u8_t;
724
typedef signed char posh_i8_t;
726
#if defined POSH_USE_LIMITS_H
728
# error This machine uses 9-bit characters. This is a warning, you can comment this out now.
729
# endif /* CHAR_BITS > 8 */
732
# if ( USHRT_MAX == 65535 )
733
typedef unsigned short posh_u16_t;
734
typedef short posh_i16_t;
736
/* Yes, in theory there could still be a 16-bit character type and shorts are
737
32-bits in size...if you find such an architecture, let me know =P */
738
# error No 16-bit type found
742
# if ( INT_MAX == 2147483647 )
743
typedef unsigned posh_u32_t;
744
typedef int posh_i32_t;
745
# elif ( LONG_MAX == 2147483647 )
746
typedef unsigned long posh_u32_t;
747
typedef long posh_i32_t;
749
error No 32-bit type found
752
#else /* POSH_USE_LIMITS_H */
754
typedef unsigned short posh_u16_t;
755
typedef short posh_i16_t;
757
# if !defined POSH_OS_PALM
758
typedef unsigned posh_u32_t;
759
typedef int posh_i32_t;
761
typedef unsigned long posh_u32_t;
762
typedef long posh_i32_t;
766
/** Minimum value for a byte */
767
#define POSH_BYTE_MIN 0
768
/** Maximum value for an 8-bit unsigned value */
769
#define POSH_BYTE_MAX 255
770
/** Minimum value for a byte */
771
#define POSH_I16_MIN ( ( posh_i16_t ) 0x8000 )
772
/** Maximum value for a 16-bit signed value */
773
#define POSH_I16_MAX ( ( posh_i16_t ) 0x7FFF )
774
/** Minimum value for a 16-bit unsigned value */
775
#define POSH_U16_MIN 0
776
/** Maximum value for a 16-bit unsigned value */
777
#define POSH_U16_MAX ( ( posh_u16_t ) 0xFFFF )
778
/** Minimum value for a 32-bit signed value */
779
#define POSH_I32_MIN ( ( posh_i32_t ) 0x80000000 )
780
/** Maximum value for a 32-bit signed value */
781
#define POSH_I32_MAX ( ( posh_i32_t ) 0x7FFFFFFF )
782
/** Minimum value for a 32-bit unsigned value */
783
#define POSH_U32_MIN 0
784
/** Maximum value for a 32-bit unsigned value */
785
#define POSH_U32_MAX ( ( posh_u32_t ) 0xFFFFFFFF )
788
** ----------------------------------------------------------------------------
789
** Sanity checks on expected sizes
790
** ----------------------------------------------------------------------------
792
POSH_COMPILE_TIME_ASSERT(posh_byte_t, sizeof(posh_byte_t) == 1);
793
POSH_COMPILE_TIME_ASSERT(posh_u8_t, sizeof(posh_u8_t) == 1);
794
POSH_COMPILE_TIME_ASSERT(posh_i8_t, sizeof(posh_i8_t) == 1);
795
POSH_COMPILE_TIME_ASSERT(posh_u16_t, sizeof(posh_u16_t) == 2);
796
POSH_COMPILE_TIME_ASSERT(posh_i16_t, sizeof(posh_i16_t) == 2);
797
POSH_COMPILE_TIME_ASSERT(posh_u32_t, sizeof(posh_u32_t) == 4);
798
POSH_COMPILE_TIME_ASSERT(posh_i32_t, sizeof(posh_i32_t) == 4);
800
#if !defined POSH_NO_FLOAT
801
POSH_COMPILE_TIME_ASSERT(posh_testfloat_t, sizeof(float)==4 );
802
POSH_COMPILE_TIME_ASSERT(posh_testdouble_t, sizeof(double)==8);
805
#if defined POSH_64BIT_INTEGER
806
POSH_COMPILE_TIME_ASSERT(posh_u64_t, sizeof(posh_u64_t) == 8);
807
POSH_COMPILE_TIME_ASSERT(posh_i64_t, sizeof(posh_i64_t) == 8);
811
** ----------------------------------------------------------------------------
812
** 64-bit pointer support
813
** ----------------------------------------------------------------------------
815
#if defined POSH_CPU_AXP && ( defined POSH_OS_TRU64 || defined POSH_OS_LINUX )
816
# define POSH_64BIT_POINTER 1
819
#if defined POSH_CPU_X86_64 && defined POSH_OS_LINUX
820
# define POSH_64BIT_POINTER 1
823
#if defined POSH_CPU_SPARC64 || defined POSH_OS_WIN64 || defined __64BIT__ || defined __LP64 || defined _LP64 || defined __LP64__ || defined _ADDR64 || defined _CRAYC
824
# define POSH_64BIT_POINTER 1
827
#if defined POSH_64BIT_POINTER
828
POSH_COMPILE_TIME_ASSERT( posh_64bit_pointer, sizeof( void * ) == 8 );
830
/* if this assertion is hit then you're on a system that either has 64-bit
831
addressing and we didn't catch it, or you're on a system with 16-bit
832
pointers. In the latter case, POSH doesn't actually care, we're just
833
triggering this assertion to make sure you're aware of the situation,
834
so feel free to delete it.
836
If this assertion is triggered on a known 32 or 64-bit platform,
837
please let us know (poshlib@poshlib.org) */
838
POSH_COMPILE_TIME_ASSERT( posh_32bit_pointer, sizeof( void * ) == 4 );
842
** ----------------------------------------------------------------------------
843
** POSH Utility Functions
845
** These are optional POSH utility functions that are not required if you don't
846
** need anything except static checking of your host and target environment.
848
** These functions are NOT wrapped with POSH_PUBLIC_API because I didn't want
849
** to enforce their export if your own library is only using them internally.
850
** ----------------------------------------------------------------------------
856
const char *POSH_GetArchString( void );
858
#if !defined POSH_NO_FLOAT
860
posh_u32_t POSH_LittleFloatBits( float f );
861
posh_u32_t POSH_BigFloatBits( float f );
862
float POSH_FloatFromLittleBits( posh_u32_t bits );
863
float POSH_FloatFromBigBits( posh_u32_t bits );
865
void POSH_DoubleBits( double d, posh_byte_t dst[ 8 ] );
866
double POSH_DoubleFromBits( const posh_byte_t src[ 8 ] );
869
float *POSH_WriteFloatToLittle( void *dst, float f );
870
float *POSH_WriteFloatToBig( void *dst, float f );
871
float POSH_ReadFloatFromLittle( const void *src );
872
float POSH_ReadFloatFromBig( const void *src );
874
double *POSH_WriteDoubleToLittle( void *dst, double d );
875
double *POSH_WriteDoubleToBig( void *dst, double d );
876
double POSH_ReadDoubleFromLittle( const void *src );
877
double POSH_ReadDoubleFromBig( const void *src );
879
#endif /* !defined POSH_NO_FLOAT */
881
extern posh_u16_t POSH_SwapU16( posh_u16_t u );
882
extern posh_i16_t POSH_SwapI16( posh_i16_t u );
883
extern posh_u32_t POSH_SwapU32( posh_u32_t u );
884
extern posh_i32_t POSH_SwapI32( posh_i32_t u );
886
#if defined POSH_64BIT_INTEGER
888
extern posh_u64_t POSH_SwapU64( posh_u64_t u );
889
extern posh_i64_t POSH_SwapI64( posh_i64_t u );
891
#endif /*POSH_64BIT_INTEGER */
893
extern posh_u16_t *POSH_WriteU16ToLittle( void *dst, posh_u16_t value );
894
extern posh_i16_t *POSH_WriteI16ToLittle( void *dst, posh_i16_t value );
895
extern posh_u32_t *POSH_WriteU32ToLittle( void *dst, posh_u32_t value );
896
extern posh_i32_t *POSH_WriteI32ToLittle( void *dst, posh_i32_t value );
898
extern posh_u16_t *POSH_WriteU16ToBig( void *dst, posh_u16_t value );
899
extern posh_i16_t *POSH_WriteI16ToBig( void *dst, posh_i16_t value );
900
extern posh_u32_t *POSH_WriteU32ToBig( void *dst, posh_u32_t value );
901
extern posh_i32_t *POSH_WriteI32ToBig( void *dst, posh_i32_t value );
903
extern posh_u16_t POSH_ReadU16FromLittle( const void *src );
904
extern posh_i16_t POSH_ReadI16FromLittle( const void *src );
905
extern posh_u32_t POSH_ReadU32FromLittle( const void *src );
906
extern posh_i32_t POSH_ReadI32FromLittle( const void *src );
908
extern posh_u16_t POSH_ReadU16FromBig( const void *src );
909
extern posh_i16_t POSH_ReadI16FromBig( const void *src );
910
extern posh_u32_t POSH_ReadU32FromBig( const void *src );
911
extern posh_i32_t POSH_ReadI32FromBig( const void *src );
913
#if defined POSH_64BIT_INTEGER
914
extern posh_u64_t *POSH_WriteU64ToLittle( void *dst, posh_u64_t value );
915
extern posh_i64_t *POSH_WriteI64ToLittle( void *dst, posh_i64_t value );
916
extern posh_u64_t *POSH_WriteU64ToBig( void *dst, posh_u64_t value );
917
extern posh_i64_t *POSH_WriteI64ToBig( void *dst, posh_i64_t value );
919
extern posh_u64_t POSH_ReadU64FromLittle( const void *src );
920
extern posh_i64_t POSH_ReadI64FromLittle( const void *src );
921
extern posh_u64_t POSH_ReadU64FromBig( const void *src );
922
extern posh_i64_t POSH_ReadI64FromBig( const void *src );
923
#endif /* POSH_64BIT_INTEGER */
925
#if defined POSH_LITTLE_ENDIAN
927
# define POSH_LittleU16(x) (x)
928
# define POSH_LittleU32(x) (x)
929
# define POSH_LittleI16(x) (x)
930
# define POSH_LittleI32(x) (x)
931
# if defined POSH_64BIT_INTEGER
932
# define POSH_LittleU64(x) (x)
933
# define POSH_LittleI64(x) (x)
934
# endif /* defined POSH_64BIT_INTEGER */
936
# define POSH_BigU16(x) POSH_SwapU16(x)
937
# define POSH_BigU32(x) POSH_SwapU32(x)
938
# define POSH_BigI16(x) POSH_SwapI16(x)
939
# define POSH_BigI32(x) POSH_SwapI32(x)
940
# if defined POSH_64BIT_INTEGER
941
# define POSH_BigU64(x) POSH_SwapU64(x)
942
# define POSH_BigI64(x) POSH_SwapI64(x)
943
# endif /* defined POSH_64BIT_INTEGER */
947
# define POSH_BigU16(x) (x)
948
# define POSH_BigU32(x) (x)
949
# define POSH_BigI16(x) (x)
950
# define POSH_BigI32(x) (x)
952
# if defined POSH_64BIT_INTEGER
953
# define POSH_BigU64(x) (x)
954
# define POSH_BigI64(x) (x)
955
# endif /* POSH_64BIT_INTEGER */
957
# define POSH_LittleU16(x) POSH_SwapU16(x)
958
# define POSH_LittleU32(x) POSH_SwapU32(x)
959
# define POSH_LittleI16(x) POSH_SwapI16(x)
960
# define POSH_LittleI32(x) POSH_SwapI32(x)
962
# if defined POSH_64BIT_INTEGER
963
# define POSH_LittleU64(x) POSH_SwapU64(x)
964
# define POSH_LittleI64(x) POSH_SwapI64(x)
965
# endif /* POSH_64BIT_INTEGER */