C language | Page 3

Not Available
byte
short2 bytes
int2 or 4 bytes
long4 bytes
An object of a given type will occupy the corresponding size in mem-
ory, and will be able to hold a different range of values. Note that these
sizes are not defined exactly like that in the ANSI standard, but the
shown values are those commonly used with microprocessors. Note
that short may be written short int and that long may be written long
int.
The type int is equivalent either to type short or to type long depending
on the target processor capabilities. For most of the existing microproc-
essors, int is equivalent to short because their internal registers are at
most 16 bits wide. The type int is an important one because it is used as
a reference type for the expressions and for the function arguments. It is
a source of problems when adapting a program to another target proces-
sor because its size may also change.
An integer type may be prefixed by the keyword signed or unsigned to
give a more accurate definition of the range of possible values. The
keyword signed means that the values hold by the variable may be pos-
itive or negative. For instance, a signed char will hold values from -128
to +127 if numbers are represented using the two’s complement con-
vention. This convention is used by all the common microprocessors.
The keyword unsigned means that the value held by the variable is pos-
itive only. An unsigned char will hold values from 0 to 255.

Declarations
2-6 C Language Overview © Copyright 2003 by COSMIC Software
2
Note that these attributes do not change the object size in memory, but
alter the way the object is handled. For instance, comparing an unsigned
integer less than zero is meaningless, and will probably lead in a com-
piler error message. Other effects of these attributes will be discussed
with the expressions and conversions.
If these keywords are not used in an integer declaration, the object has a
default attribute depending on its type.
short
int
are signed by default
long
char
is implementation dependant
A plain char object may be either signed or unsigned, depending on
which attribute is simpler to implement. UNIX style compilers have
historically used chars signed by default, but this behaviour may not be
efficient on small microprocessors. If the operation of sign-extending a
char to an int costs more machine instructions than clearing the extra
bits, the default attribute for a plain char type will be unsigned. Other-
wise, it will be signed. Note that it is possible to modify the default
behaviour of the COSMIC compilers by using a specific option on the
parser (-u).
There is another way to define an integer variable, by defining the range
of possible values. An enumeration is an integer type defined by a list
of identifiers. The compiler assigns an integer value to each of these
identifiers, or uses a specific value declared with the identifier.
Each of these identifiers becomes a new constant for the compiler, and
by examining the smallest and the largest values of the enumeration, the
compiler will choose the smallest integer type large enough to hold all
the values. The enumeration is a convenient way to define a set of codes
and at the same time the most efficient variable type to hold all of these
codes.

Declarations
© Copyright 2003 by COSMIC Software
C Language Overview 2-7
Bit Type
The bit type is
_Bool1 bit
The bit type is an extension to the C standard and is implemented con-
formant to the boolean type of the C99 standard. It is not available on
all the Cosmic compilers, and mainly for those processors providing
efficient instructions for bit handling.
Objects of this type are packed into bytes or words in memory and allo-
cated to a memory section appropriate for access by efficient bit han-
dling instructions. Such objects have only the two possible values true
and false usually coded as 1 and 0.
Real Types
A real type is one of
float4 bytes
double8 bytes
long doublemore than 8 bytes
The type long double is generally used to describe internal types of
arithmetic coprocessors, handling reals on 9 or 10 bytes, in order to
avoid any loss of precision when storing an intermediate result in mem-
ory. The physical coding of a real number is not fixed by the ANSI
standard, but most compilers use the IEEE754 encoding mechanism. It
is probably not the most efficient for a small microprocessor, but it is a
convenient way to unify the encoding of reals over the various compil-
ers and processors. With the IEEE754 coding, a float variable holds real
numbers with 7 digits precision and an exponent range of 10 to the
power +
38. A double variable holds real numbers with 14 digits preci-
sion and an exponent range of 10 to the power +
308.
For some small target processors, only the type float is supported by the
compiler. In that case, all the types are allowed in the program syntax,
but they are all mapped to the type float internally. This mechanism is
also available as an option for larger targets if the application does not
require a very accurate precision. It reduces the memory usage and the
time needed to
Continue reading on your phone by scaning this QR Code

 / 24
Tip: The current page has been bookmarked automatically. If you wish to continue reading later, just open the Dertz Homepage, and click on the 'continue reading' link at the bottom of the page.