Article View: comp.lang.modula2
Article #4263Re: Cardinal numbers
From: Alan Lovejoy
Date: Sun, 22 May 1988 05:54
Date: Sun, 22 May 1988 05:54
35 lines
1648 bytes
1648 bytes
In article <1101@sask.UUCP> intbook@sask.UUCP (Dave Daoust) writes:
/
/Is the following program legal? What is displayed?
/
/
/MODULE N;
/FROM InOut IMPORT WriteCard, WriteLn;
/PROCEDURE Out(S : ARRAY OF CHAR);
/BEGIN
/ WriteCard(HIGH(S), 0);
/ WriteLn;
/END Out;
/BEGIN
/ Out("");
/END N.
This legal program outputs the digit 0 followed by a newLine.
It is impossible to have an array whose length is zero, since that
would require its ending index to be less than its starting index.
So the type of "" is ARRAY [0..0] OF CHAR, and its length is therefore
one character. Normally, the compiler stores 0C in such a string.
Therefore, HIGH never needs to return -1 as the maximum index of an
array. But open array parameters which are strings should always be
checked for the presence of 0C, starting with index 0.
Marking the end of strings with a special character is an irredeemably
brain-damaged idea. The fact that C does it is no excuse.
--
Alan Lovejoy; alan@pdn; 813-530-8241; Paradyne Corporation: Largo, Florida.
Disclaimer: Do not confuse my views with the official views of Paradyne
Corporation (regardless of how confusing those views may be).
Motto: Never put off to run-time what you can do at compile-time!
Technical Details
Message-ID:
<3213@pdn.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!pdn!alanReferences:
<1101@sask.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!pdn!alan From: alan@pdn.UUCP (Alan Lovejoy) Newsgroups: comp.lang.modula2 Subject: Re: Cardinal numbers Keywords: HIGH, WriteCard Message-ID: <3213@pdn.UUCP> Date: 22 May 88 05:54:56 GMT References: <1101@sask.UUCP> Reply-To: alan@pdn.UUCP (0000-Alan Lovejoy) Organization: Paradyne Corporation, Largo, Florida Lines: 35