Home Libraries Author Links

basetype.h File Reference


Detailed Description

Declaration of basic macro and type definitions depending on system specific settings.

Version:
1.11-r319
Date:
2007-11-15 17:34:58 (Tom)
Author:
Tom Michaelis
SysToMath
Wittelsbacherstr. 7
D-80469 Munich
Contact:
http://www.SysToMath.com
mailto:Tom.Michaelis@SysToMath.com
This C header file contains general macros and type definitions used by the objects of the SysToMath Base C Library (stmbase). It is included in each header and program file of stmbase. So for the user of stmbase it is not necessary to include basetype.h, if she includes one of the other header files of stmbase.

Definition in file basetype.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Byte Order

#define __BIG_ENDIAN   4321
 Representation of the big endian byte order.
#define __LITTLE_ENDIAN   1234
 Representation of the little endian byte order.
#define __BYTE_ORDER   __LITTLE_ENDIAN
 Actual byte order.

Boolean Data Type

Definition of the boolean data type and its value constants.

#define StmFalse   0
 Value false for boolean type.
#define StmTrue   1
 Value true for boolean type.
typedef int StmBool
 Boolean type.

Abstract Data Types

Definition of abstract data types.

#define StmAbstractType(Type)
 Definition of an abstract data type Type implemented by a structure.
#define StmAbstractTypeDefine(Type)
 Definition of an abstract data type Type implemented by an arbitrary type.

Alignment

Type definition and macros for alignment issues.

#define StmAlignUnits(n)   (((n) + sizeof (StmAlign) - 1) / sizeof (StmAlign))
 Number of StmAlign blocks for n bytes.
#define StmTypeAlignUnits(Type)   (StmAlignUnits (sizeof (Type)))
 Number of StmAlign blocks for one Type object.
typedef long StmAlign
 StmAlign shall satisfy the allignment requirements of every type.

Miscellanous Macros

Definition of miscellaneous macros.

#define StmSizeofMember(agg, mem)   (sizeof (((agg *) NULL) -> mem))
 Size of the member mem of an aggregat agg.
#define StmElements(vector)   (sizeof (vector) / sizeof (vector [0]))
 Element count of an array vector.
#define StmCharBits   CHAR_BIT
 Number of bits per character.
#define StmByteBits   StmCharBits
 Number of bits per byte.
#define StmUshortBits   (sizeof (unsigned short int) * StmByteBits)
 Number of bits per unsigned short int.
#define StmShortBits   StmUshortBits
 Number of bits per short int.
#define StmUintBits   (sizeof (unsigned int) * StmByteBits)
 Number of bits per unsigned int.
#define StmIntBits   StmUintBits
 Number of bits per int.
#define StmUlongIntBits   (sizeof (unsigned long int) * StmByteBits)
 Number of bits per unsigned long int.
#define StmLongIntBits   StmUlongIntBits
 Number of bits per long int.
#define StmBytesForBits(n)   (((n) + StmByteBits - 1) / StmByteBits)
 Number of bytes needed for a bit vector of n bits.
#define StmTwoToThe(nth)   ((size_t) 1 << (nth))
 Represents 2 to the nth.
#define StmId(key)
 Represents the unquoted string key as StmDword.
#define StmIdx(key)
 Represents the quoted string key as StmDword.

Flag Field And Flag Macros

Macros defining and handling flag fields and flags implemented as enumerators.

The advantage of these macros over bit field declarations is that they are less implementation dependent regarding the placement of bits within a scalar type. Nevertheless beware of the dependency on the endianness of the architecture used. To neutralize that dependency use the endianness macros __BYTE_ORDER, __LITTLE_ENDIAN and __BIG_ENDIAN.

Example:
      typedef enum
      {
          StmDeclareFlag (Disabled, 0),
          StmDeclareFlag (Conditional, DisabledEnd),
          StmDeclareFlagField (ImageFormat, ConditionalEnd, 2),
          ImageFormatUnknown   =  0,
          ImageFileMissing     =  1,
          ImageFormatPortrait  =  2,
          ImageFormatLandscape =  3,
          StmDeclareFlag (PlaylistItem, ImageFormatEnd)
      }
      Flags;

      unsigned int flags = 0;
      StmSetFlag (flags, PlaylistItem, StmTrue);
      StmSetFlagField (flags, ImageFormat, ImageFormatPortrait);
          ...
      if (!StmGetFlag (flags, Disabled) &&
          StmGetFlagField (flags, ImageFormat) != ImageFormatLandscape)
      {
          ...
      }


#define StmDeclareFlagField(name, beginBit, bitLength)
 Declares enumerators for a flag field named name with begin bit beginBit and bit length bitLength.
#define StmGetFlagField(variable, name)   (((variable) & name) >> name##Begin)
 Gets the value of the flag field name of variable.
#define StmSetFlagField(variable, name, value)
 Sets the the flag field name of variable to value.
#define StmDeclareFlag(name, beginBit)   StmDeclareFlagField (name, beginBit, 1)
 Declares enumerators for a flag named name with begin bit beginBit.
#define StmGetFlag(variable, name)   (StmGetFlagField (variable, name))
 Gets the value of the flag name of variable.
#define StmSetFlag(variable, name, value)   StmSetFlagField (variable, name, (value))
 Sets the the flag name of variable to value.

8 Bit Data Types

typedef unsigned char StmByte
 One unsigned byte of data.
typedef unsigned char StmUint8
 One unsigned byte of data.
typedef signed char StmInt8
 One signed byte of data.
typedef StmByteStmAddr
 Byte address.

16 Bit Data Types

typedef unsigned short int StmWord
 Unsigned quantity consisting of two bytes of data.
typedef unsigned short int StmUint16
 Unsigned quantity consisting of two bytes of data.
typedef short int StmInt16
 Signed quantity consisting of two bytes of data.

32 Bit Data Types

typedef unsigned int StmDword
 Unsigned quantity consisting of four bytes of data.
typedef unsigned int StmUint32
 Unsigned quantity consisting of four bytes of data.
typedef int StmInt32
 Signed quantity consisting of four bytes of data.

64 Bit Data Types

typedef unsigned long long int StmQword
 Unsigned quantity consisting of eight bytes of data.
typedef unsigned long long int StmUint64
 Unsigned quantity consisting of eight bytes of data.
typedef long long int StmInt64
 Signed quantity consisting of eight bytes of data.


© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).