Home Libraries Author Links

Basetype: Basic Macro and Type Definitions
[SysToMath Base C Library]

Collaboration diagram for Basetype: Basic Macro and Type Definitions:

Detailed Description

Basic macro and type definitions depending on system specific settings.

Macro and type definitions for inlining, endianness, abstract data types, scalar data types, alignment and flag handling. These definitions are used throughout the other SysToMath Base C Library modules.


Files

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

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.

Boolean Data Type

Definition of the boolean data type and its value constants.

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

Alignment

Type definition and macros for alignment issues.

typedef long StmAlign
 StmAlign shall satisfy the allignment requirements of every type.
#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.

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.

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.

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.


Define Documentation

#define __BIG_ENDIAN   4321

Representation of the big endian byte order.

Definition at line 100 of file basetype.h.

#define __LITTLE_ENDIAN   1234

Representation of the little endian byte order.

Definition at line 104 of file basetype.h.

#define __BYTE_ORDER   __LITTLE_ENDIAN

Actual byte order.

Definition at line 108 of file basetype.h.

#define StmFalse   0

Value false for boolean type.

Examples:
conditiontest.c, cuglify.c, dsettst.c, mutextest.c, namedconditiontest.c, namedmutextest.c, semaphoretest.c, sharedmemorytest.c, and systemuniquetest.c.

Definition at line 212 of file basetype.h.

Referenced by commout(), gatherout(), main(), out(), pnlout(), pout(), and readline().

#define StmTrue   1

Value true for boolean type.

Examples:
cuglify.c, dsettst.c, and matchtst.c.

Definition at line 216 of file basetype.h.

Referenced by bout(), cnlout(), commout(), main(), out(), pnlout(), pout(), readline(), and setclbeg().

#define StmAbstractType ( Type   ) 

Value:

typedef struct Type##Impl_ Type##Impl_;                                       \
typedef Type##Impl_ *Type;                                                    \
typedef const Type##Impl_ *Const##Type;
Definition of an abstract data type Type implemented by a structure.

Parameters:
[in] Type Name of the abstract data type to be defined.
Effects:
The macro :StmAbstractType defines the abstract data type flavours
  • Type as a pointer type to the implementation structure Type##Impl_.
  • Const##Type as a pointer type to the constant implementation structure Type##Impl_.
Requires:
Type##Impl_ shall be the name of a structure which need not be defined yet.
Note:
When declaring an abstract data type do not append a trailing semicolon to the macro call.
Examples:
sharedmemorytest.c, and systemuniquetest.c.

Definition at line 247 of file basetype.h.

#define StmAbstractTypeDefine ( Type   ) 

Value:

typedef Type##Impl_ *Type;                                                    \
typedef const Type##Impl_ *Const##Type;
Definition of an abstract data type Type implemented by an arbitrary type.

Parameters:
[in] Type Name of the abstract data type to be defined.
Effects:
The macro :StmAbstractTypeDefine defines the abstract data type flavours
  • Type as a pointer type to the implementation type Type##Impl_.
  • Const##Type as a pointer type to the constant implementation type Type##Impl_.
Requires:
Type##Impl_ shall be the name of an already known type.
Note:
When declaring an abstract data type do not append a trailing semicolon to the macro call.

Definition at line 269 of file basetype.h.

#define StmAlignUnits (  )     (((n) + sizeof (StmAlign) - 1) / sizeof (StmAlign))

Number of StmAlign blocks for n bytes.

The macro StmAlignUnits represents the least number of blocks of size sizeof (StmAlign) being able to contain a buffer of n bytes.

Definition at line 285 of file basetype.h.

#define StmTypeAlignUnits ( Type   )     (StmAlignUnits (sizeof (Type)))

Number of StmAlign blocks for one Type object.

The macro StmTypeAlignUnits represents the least number of blocks of size sizeof (StmAlign) being able to contain one Type object.

Definition at line 291 of file basetype.h.

#define StmSizeofMember ( agg,
mem   )     (sizeof (((agg *) NULL) -> mem))

Size of the member mem of an aggregat agg.

Definition at line 307 of file basetype.h.

#define StmElements ( vector   )     (sizeof (vector) / sizeof (vector [0]))

Element count of an array vector.

Examples:
cuglify.c, and dsettst.c.

Definition at line 311 of file basetype.h.

Referenced by main().

#define StmCharBits   CHAR_BIT

Number of bits per character.

Definition at line 315 of file basetype.h.

#define StmByteBits   StmCharBits

Number of bits per byte.

Examples:
dsettst.c.

Definition at line 319 of file basetype.h.

Referenced by randomInt().

#define StmUshortBits   (sizeof (unsigned short int) * StmByteBits)

Number of bits per unsigned short int.

Definition at line 323 of file basetype.h.

#define StmShortBits   StmUshortBits

Number of bits per short int.

Definition at line 327 of file basetype.h.

#define StmUintBits   (sizeof (unsigned int) * StmByteBits)

Number of bits per unsigned int.

Definition at line 331 of file basetype.h.

#define StmIntBits   StmUintBits

Number of bits per int.

Definition at line 335 of file basetype.h.

#define StmUlongIntBits   (sizeof (unsigned long int) * StmByteBits)

Number of bits per unsigned long int.

Definition at line 339 of file basetype.h.

#define StmLongIntBits   StmUlongIntBits

Number of bits per long int.

Definition at line 343 of file basetype.h.

#define StmBytesForBits (  )     (((n) + StmByteBits - 1) / StmByteBits)

Number of bytes needed for a bit vector of n bits.

Definition at line 347 of file basetype.h.

#define StmTwoToThe ( nth   )     ((size_t) 1 << (nth))

Represents 2 to the nth.

Definition at line 351 of file basetype.h.

#define StmId ( key   ) 

Value:

(StmDword) (#key [0] ?                                                         \
            #key [1] ?                                                         \
            #key [2] ?                                                         \
            #key [3] ?                                                         \
            #key [3] + 256 * (#key [2] + 256 * (#key [1] + 256 * #key [0])) :  \
            #key [2] + 256 * (#key [1] + 256 * #key [0]) :                     \
            #key [1] + 256 * #key [0] :                                        \
            #key [0] :                                                         \
            0)
Represents the unquoted string key as StmDword.

Examples:
cuglify.c, and dsettst.c.

Definition at line 355 of file basetype.h.

Referenced by main().

#define StmIdx ( key   ) 

Value:

(StmDword) (key [0] ?                                                          \
            key [1] ?                                                          \
            key [2] ?                                                          \
            key [3] ?                                                          \
            key [3] + 256 * (key [2] + 256 * (key [1] + 256 * key [0])) :      \
            key [2] + 256 * (key [1] + 256 * key [0]) :                        \
            key [1] + 256 * key [0] :                                          \
            key [0] :                                                          \
            0)
Represents the quoted string key as StmDword.

Definition at line 368 of file basetype.h.

#define StmDeclareFlagField ( name,
beginBit,
bitLength   ) 

Value:

name##Begin  = (beginBit),                                                     \
name##Length = (bitLength),                                                    \
name##End    = ((beginBit) + (bitLength)),                                     \
name         = ((((size_t) 1 << (bitLength)) - 1) << (beginBit))
Declares enumerators for a flag field named name with begin bit beginBit and bit length bitLength.

Definition at line 421 of file basetype.h.

#define StmGetFlagField ( variable,
name   )     (((variable) & name) >> name##Begin)

Gets the value of the flag field name of variable.

Definition at line 429 of file basetype.h.

#define StmSetFlagField ( variable,
name,
value   ) 

Value:

do                                                                             \
{                                                                              \
    (variable) &= ~name; (variable) |= ((value) << name##Begin) & name;        \
}                                                                              \
while (0)
Sets the the flag field name of variable to value.

Definition at line 434 of file basetype.h.

#define StmDeclareFlag ( name,
beginBit   )     StmDeclareFlagField (name, beginBit, 1)

Declares enumerators for a flag named name with begin bit beginBit.

Definition at line 443 of file basetype.h.

#define StmGetFlag ( variable,
name   )     (StmGetFlagField (variable, name))

Gets the value of the flag name of variable.

Definition at line 448 of file basetype.h.

#define StmSetFlag ( variable,
name,
value   )     StmSetFlagField (variable, name, (value))

Sets the the flag name of variable to value.

Definition at line 453 of file basetype.h.


Typedef Documentation

typedef unsigned char StmByte

One unsigned byte of data.

Examples:
dsettst.c.

Definition at line 119 of file basetype.h.

typedef unsigned char StmUint8

One unsigned byte of data.

Definition at line 123 of file basetype.h.

typedef signed char StmInt8

One signed byte of data.

Definition at line 127 of file basetype.h.

typedef StmByte* StmAddr

Byte address.

Definition at line 131 of file basetype.h.

typedef unsigned short int StmWord

Unsigned quantity consisting of two bytes of data.

Definition at line 141 of file basetype.h.

typedef unsigned short int StmUint16

Unsigned quantity consisting of two bytes of data.

Definition at line 145 of file basetype.h.

typedef short int StmInt16

Signed quantity consisting of two bytes of data.

Definition at line 149 of file basetype.h.

typedef unsigned int StmDword

Unsigned quantity consisting of four bytes of data.

Examples:
cuglify.c, and dsettst.c.

Definition at line 159 of file basetype.h.

typedef unsigned int StmUint32

Unsigned quantity consisting of four bytes of data.

Definition at line 163 of file basetype.h.

typedef int StmInt32

Signed quantity consisting of four bytes of data.

Definition at line 167 of file basetype.h.

typedef unsigned long long int StmQword

Unsigned quantity consisting of eight bytes of data.

Definition at line 191 of file basetype.h.

typedef unsigned long long int StmUint64

Unsigned quantity consisting of eight bytes of data.

Definition at line 195 of file basetype.h.

typedef long long int StmInt64

Signed quantity consisting of eight bytes of data.

Definition at line 199 of file basetype.h.

typedef int StmBool

Boolean type.

Examples:
cuglify.c, and dsettst.c.

Definition at line 220 of file basetype.h.

typedef long StmAlign

StmAlign shall satisfy the allignment requirements of every type.

Definition at line 295 of file basetype.h.


© Copyright Tom Michaelis 2002-2007

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