Use dimensionless raw C types

It's acceptable to use a raw C type under certain circumstances, such as when the quantity is machine dependent, or when it can be characterized as a dimensionless number (for example, a smallint). Otherwise, it's best to give yourself flexibility.

However, types that merely wrap existing C types are not helpful:

    typedef unsigned char UChar;        // Bad usage
Either use a raw C type because it's a dimensionless number and falls within the definition of the C type, or define a typedef based on the function of the type, not its concrete representation. To help you with this, the header file PrimitiveTypes.h
contains useful definitions of primitive types. Two ANSI C header files, stddef.h and limits.h, contain definitions as well, here are two:

size_t The type returned by the built-in C sizeof function. This is useful for representing the sizes of things.
ptrdiff_t A type that can represent the difference between any two pointers.

You might have noticed that these names don't conform to Taligent conventions. In the interest of clarity and portability, it is better to use the names as defined by ISO/ANSI C. However, a useful non-ISO/ANSI C type is void*, which is for pointers to raw storage.

NOTE If a data type is unsigned, declare it unsigned; this helps avoid nasty bugs down the road.

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker