Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP Pascal/HP-UX Programmer's Guide > Chapter 4 Predefined Pascal Constants, Data Types, and Modules

Shortint

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

The predefined data type shortint is an integer in the range -32768..32767 that is stored in 16 bits. (In contrast, if you declare a variable to be in that range, it is stored in 32 bits.) The type shortint has the following uses:

  • If you want to access an external non-Pascal routine that has a formal parameter of a type whose range is -32768..32767, and uses 16-bits of storage, you can declare a corresponding formal Pascal parameter of type shortint, and it will be compatible.

  • For Pascal/V compatibility.

To determine whether a type T is assignment compatible with the type shortint, you can treat shortint as a subrange of integer. This means that you can assign a variable v of type T to a variable sv of type shortint if:

  • The type T is integer or a subrange of integer.

  • The value of v is within the range of shortint (-32768..32767).

    If the ranges of T and shortint do not overlap, the assignment sv:=v causes a compile-time error. If the ranges of T and shortint do overlap, but the value of v is outside the range of shortint the assignment sv:=v causes a run-time error.

Example

PROGRAM prog;

TYPE
T1 = integer; {overlaps shortint range}
T2 = -10..40000; {overlaps shortint range}
T3 = 40000..50000; {does not overlap shortint range}

VAR
v1 : T1; {sv:=v1 may be legal, depending on value of v1}
v2 : T2; {sv:=v2 may be legal, depending on value of v2}
v3 : T3; {sv:=v3 is never legal}
sv : shortint;

BEGIN
v1 := 10;
sv := v1; {legal assignment}

v1 := 45000;
sv := v1; {causes run-time error}

v2 := 400;
sv := v2; {legal assignment}

v2 := 35000;
sv := v2; {causes run-time error}

v3 := 40000;
sv := v3; {causes compile-time error}
END.
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.