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 5 Allocation and Alignment

Strings

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Glossary

 » Index

A string is allocated four bytes for its current length (an integer), one byte per character, and one "housekeeping" byte. The number of characters is the string's declared maximum length. The "housekeeping" byte is only accessible to some of the standard string functions.

The HP Pascal packing algorithm aligns strings on 4-byte boundaries in all structures. Because the current length (an integer) is allocated four bytes, eight bytes is the smallest possible string allocation.

The formula for the number of bytes allocated to a string is:

Figure 5-23 String Byte Allocation

String Byte Allocation

Example

VAR
s1 : string[10];
s2 : string[7];

The string s1 takes 16 bytes:

(((4 + 10 + 1) + 3) DIV 4) * 4 =
(18 DIV 4) * 4 =
4 * 4 = 16

The allocation is:

Figure 5-24 Strings Example 1

Strings Example 1

The string s2 takes 12 bytes:

(((4 + 7 + 1) + 3) DIV 4) * 4 =
(15 DIV 4) * 4 =
3 * 4 = 12

The allocation is:

Figure 5-25 Strings Example 2

Strings Example 2
Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© Hewlett-Packard Development Company, L.P.