pTAL Guidelines for TAL Programmers
Coding Guidelines
pTAL Guidelines for TAL Programmers—527256-002
2-10
Overflow Traps
Overflow Traps
Guideline: Do not assume that overflow causes a trap on intermediate operators
within an expression.
If traps are enabled in a TAL program, an overflow exception causes an immediate
trap.
In Example 2-6 on page 2-10, the addition operator causes overflow and a trap occurs.
The program retains control only if it has established a trap handler; otherwise, the
program abends.
In a pTAL program running as a native process, overflow might not be detected at the
same location as it is when you run the same program as a TNS process. In some
cases, a program that causes overflow in a TNS process might not cause overflow in a
native process.
Pointers and Addresses
In TAL, a value is an address only because you store the value into a pointer and use
the pointer to access data. Any INT or INT(32) value can be an address and, therefore,
you can manipulate addresses using standard arithmetic operators.
In pTAL, addresses and integers are distinctly different data types. You can store into a
pointer only an address whose address type corresponds to the address type of the
pointer. You cannot store an integer into a pointer.
pTAL supports 10 address types, none of which are the same as integers.
In pTAL, each pointer has two data types associated with it:
•
Object data type: the data type of the objects to which the pointer points
•
Address type: the data type of the addresses that you store into the pointer
On TNS architecture, the 10 address types are distinguished from each other by:
•
The location of the referenced data, which is one of:
°
The user data segment
°
An extended data segment
°
A code segment
°
The system globals segment
Example 2-6. Overflow Trap
PROC p;
BEGIN
INT i := 32767;
i := i + 1 - f(j);
END;