/* ======================================================================= * PROGRAMMER "BAHN, William" * TITLE "Integer Storage Size Type Definitions" * CREATED 06 FEB 07 * MODIFIED 06 FEB 07 * FILENAME "bytes.c" * ======================================================================= * GENERAL DESCRIPTION * * NOTE: ANY AVAILABLE "USER GUIDE" IS IN THE ASSOCIATED HEADER FILE. * * This file contains type definitions so that porting from one processor * to another is simpler. * * ======================================================================= */ #include "bytes.h" int VerifyBYTE(void) { return (8*sizeof(BYTE) != BITSinBYTE); } int VerifyWORD(void) { return (8*sizeof(WORD) != BITSinWORD); } int VerifyDWORD(void) { return (8*sizeof(DWORD) != BITSinDWORD); } int VerifyQWORD(void) { return (8*sizeof(QWORD) != BITSinQWORD); } unsigned int VerifySIZES(unsigned int maxlength) { unsigned int flags; unsigned int mask; // Generate a flag vector with a 1 set anyplace that does not // verify properly. Note that the bit position is equal to base-2 // log of the number of bytes in the integer type. flags = 0; flags = (flags << 1) + VerifyQWORD(); flags = (flags << 1) + VerifyDWORD(); flags = (flags << 1) + VerifyWORD(); flags = (flags << 1) + VerifyBYTE(); // Convert length from bits to smallest compatible number of bytes. maxlength = (maxlength/8) + ((maxlength%8)?1:0); // Generate a mask that is set only in those flag positions of interest. if (maxlength) // report on sizes up to and including maxlength. for (mask = 0; maxlength > 0; maxlength /= 2) { mask = (mask << 1) + 1; if ((maxlength > 1)&&(maxlength%2)) mask = (mask << 1) + 1; } else // report on all defined sizes mask = ~0; return (flags & mask); }