1

I searched in Turbo Pascal 6 the complete reference for "rset" and "lset" - statements of QB 4.5 for justifying strings inside their variables bytes - equivalents in Turbo Pascal and found no result as if Turbo Pascal doesn't need these statements or Turbo Pascal is always justifying strings to left. Is this true?

Ahmed Crow
  • 101
  • 4

1 Answers1

2

In Turbo Pascal 6.0 the string type reserves 256 bytes of memory.

s: string;

The memory layout is that the first byte (value 0..255) indicates the length of the string. The following bytes hold the characters, always left aligned.

A variation of the previous is that you can declare string variables with a maximum length, like f.ex.

s: string[10];

This example will reserve 11 bytes of memory. Again the first byte indicates length of the actual string (value in this case 0..10).

The memory content after a statement like

s := 'test';

will be

4, 't', 'e', 's', 't', #0, #0, #0, #0, #0, #0

There is no statement to modify the character allocation to right align the character data (like RSET in QBasic).

However, in theory, you may precede a string with a series of null characters, e.g s :=#0#0#0#0#0#0+'test';, to achieve a similar effect, but the length will become the length of the string variable.

10, #0, #0, #0, #0, #0, #0, 't', 'e', 's', 't'

The null chars are in this case part of the string, and this might be problematic. A null char might be taken for the end of the string. Also, as the null chars might be omitted by e.g. a printing procedure in some case and not in other cases. This could lead to misalignment of data in printouts, or other.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54