Common
IntroductionThis header contains common defines, macros and functions to be shared throughout the WAC project. GroupsBitRotatesRotates X COUNT bits to the left or right.
ctype safe macrosWrappers for the ctype.h macros make them safe when used with signed characters. DiscussionSome implementations of the ctype.h macros use the character value to directly index into a table. This can lead to crashes and other problems when used with signed characters if the character value is greater than 127 because the values 128-255 will appear to be negative if viewed as a signed char. A negative subscript to an array causes it to index before the beginning and access invalid memory. To work around this, these *_safe wrappers mask the value and cast it to an unsigned char. Group members:
Functions
BitArrayMacros for working with bit arrays. #define BitArray_MinBytes( ARRAY, N_BYTES ) memrlen( (ARRAY), (N_BYTES) ) DiscussionThis treats bit numbers starting from the left so bit 0 is 0x80 in byte 0, bit 1 is 0x40 in bit 0, bit 8 is 0x80 in byte 1, etc. For example, the following ASCII art shows how the bits are arranged: 1 1 1 1 1 1 1 1 1 1 2 2 2 2 Bit 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | x |x | x x| = 0x20 0x80 0x41 (bits 2, 8, 17, and 23). +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Byte 0 1 2 See Also
MaxReturns the greater of X and Y. #if( !defined( Max ) ) #define Max( X, Y ) #endif MinReturns the lesser of X and Y. #if( !defined( Min ) ) #define Min( X, Y ) #endif Macro Definitions
BitArray_MinBytesMacros for working with bit arrays. #define BitArray_MinBytes( ARRAY, N_BYTES ) memrlen( (ARRAY), (N_BYTES) ) DiscussionThis treats bit numbers starting from the left so bit 0 is 0x80 in byte 0, bit 1 is 0x40 in bit 0, bit 8 is 0x80 in byte 1, etc. For example, the following ASCII art shows how the bits are arranged: 1 1 1 1 1 1 1 1 1 1 2 2 2 2 Bit 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | x |x | x x| = 0x20 0x80 0x41 (bits 2, 8, 17, and 23). +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Byte 0 1 2 See Also
|