🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4215

Re: CHAR-String compatibility

#4215
From: chrisj
Date: Sat, 23 Apr 1988 17:30
41 lines
2534 bytes
In Message-ID: <INFO-M2%88042209060985@DB0TUI11>, HPA111@DE0HRZ1A.BITNET
("Michael Drechsler +49  343062", 0201) asks about passing a single CHAR
actual parameter to a formal parameter of type ARRAY OF CHAR, or in fact
passing a value of Anytype to a formal parameter of type ARRAY OF Anytype.

Nuthin' doin'.  A quoted literal is a string of some length or other,
even if the length happens to be 1.  That a quoted string of length 1,
although assignable to variable or passable to a parameter of an ARRAY
OF CHAR type, is ALSO compatible with (can be assigned to, and compared
with) type CHAR is a special case for strings only, stated on p. 155 of
3rd edition of PIM2.  (Language report, Section 9.1, Assignments).

When you pass a single character between quote marks to a parameter of
type ARRAY OF CHAR, you are passing a string of length 1, not a character.
It is not at all the same as passing the value of a variable of type CHAR.

Passing a value to a procedure is like assigning the value to a variable
of the same type as the declared type of the parameter, and is allowed
under the same circumstances.

    PROCEDURE P (a : ARRAY OF CHAR);BEGIN END P;
    VAR ch  : CHAR;
        ca  : ARRAY [0..0] OF CHAR;

    ca := ch;       (* WRONG -- TYPES NOT COMPATIBLE *)
    IF ca < ch THEN ... END;  (* WRONG -- TYPES NOT COMPATIBLE *)
    P (ch);         (* WRONG -- TYPES NOT COMPATIBLE *)

    ca [0] := ch;   (* ok *)
    IF ca [0] > ch THEN ... END; (* ok *)

    P (ca);         (* ok *)
    P ("A");        (* String of length 1, same as the previous line. *)

Only in the case of the magic type SYSTEM.WORD (and SYSTEM.BYTE on some
implementations), do you get the special exception that something other
than an array can be passed to a parameter of type ARRAY OF WORD.

Christopher Jewell                |  If God had meant for us to fly, He
chrisj@cup.portal.com             |  would NEVER have given us the railways.
ucbvax!sun!cup.portal.com!chrisj  |                     -- Flanders & Swan
Technical Details
Message-ID: <8804222349.1.120@cup.portal.com>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!rutgers!gatech!mcnc!decvax!decwrl!ucbvax!cup.portal.COM!chrisj

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!mailrus!tut.cis.ohio-state.edu!rutgers!gatech!mcnc!decvax!decwrl!ucbvax!cup.portal.COM!chrisj
From: chrisj@cup.portal.COM
Newsgroups: comp.lang.modula2
Subject: Re: CHAR-String compatibility
Message-ID: <8804222349.1.120@cup.portal.com>
Date: 23 Apr 88 17:30:54 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Reply-To: Info-Modula2 Distribution List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu>
Organization: The Internet
Lines: 40