Overflow protection, Stand-alone files, Overflow protection -31 stand-alone files -31 – National Instruments AutoCode NI MATRIX User Manual

Page 48

Advertising
background image

Chapter 2

C Language Reference

© National Instruments Corporation

2-31

AutoCode Reference

The UTs appear as

typedef

statements in the generated C code. For

example:

typedef volts RT_SBYTE03;

This code defines the data type called volts to be a signed byte with radix
position 3.

Overflow Protection

Overflow is defined as loss of significance—that is, a computation losing
bits in the integer part of the number. The term underflow is used to mean
overflow on a negative number.

An Overflow Protection capability is provided to protect against overflows.
Overflow Protection consists in detecting an overflow condition and
replacing the overflowed number with the extremal value for the data type
of the number—the maximum positive number if the overflowed number
was positive; the maximum negative number if it was negative.

Overflow can be efficiently detected in assembly code by examining the
processor status flags, whereas in C, these flags are not available, making
it necessary to test the results for consistency.

Most macros and functions with overflow protection have been combined
into sets of signed and unsigned macros and functions, and combinations
of both. This was done because overflow protection is different for signed
and unsigned operands. This difference is due to the difference in lower and
upper limits of signed and unsigned types. An unsigned type has 0 as the
lower limit, whereas a signed type has a negative number as the lower limit.
However, given the same word length and value position, the upper limit of
a signed type is always smaller than the upper limit of an unsigned type.

Overflow protection is performed in all macros and functions that have a “p”
at the end of the macro name. Examples of these macros are listed in the

Conversion Macros

section and the

Arithmetic Macros

section.

Overflow protection is controlled by the

-ovfp

option. Specifying

-ovfp

0

causes generation of unprotected macros, and specifying

-ovfp 1

causes

generation of protected macros. The default is to generate protected
macros.

Stand-Alone Files

All of the stand-alone files, with the exception of

sa_types.h

, have a

common prefix

sa_fx

, indicating fixed-point functionality.

Advertising