I would like to add:
as explained, the types integer and char are incompatibel in Pascal.
Furthermore, char in Pascal is NOT a computational type; you cannot do
arithmetic with chars, and there is no sign with chars (much the same as
in PL/1,
for example). To do arithmetic with chars, you need the conversion
functions ORD and CHR.
This all seems quite natural to me; the C idea that chars are small
integers and therefore have
a sign is strange IMO.
On the other hand, Pascal supports ANY standard or scalar or subrange
type as index type
for arrays, for example:
var howoften : array [char] of integer ;
ch: char;
...
read (ch);
howoften [ch] := howoften [ch] + 1;
the array howoften is used to count the occurence of chars in an input
file, for example.
And: if you want to have small integers (1 byte size), Pascal supports
them, too (with subranges):
type byte = - 128 .. 127;
var x : byte;
if your compiler, supports this, the variable x will use 1 byte and
allow normal integer arithmetic.
Kind regards
Bernd
Am 27.04.2020 um 03:49 schrieb Bernd Oppolzer:
Compare this to Pascal for example, where char and integer are two
different and
incompatible types. To do the same as above in Pascal, you need
conversion functions
(which are part of the Pascal standard):
var c: char;
c := chr (ord ('A') + 1);
c := chr (ord (c) - ord ('A') + ord ('a'));
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN