Thread View: net.lang.pascal
3 messages
3 total messages
Started by Russell Shilling
Sat, 01 Sep 1984 00:15
Bug in 4.2 BSD Pascal implementation ???
Author: Russell Shilling
Date: Sat, 01 Sep 1984 00:15
Date: Sat, 01 Sep 1984 00:15
38 lines
2059 bytes
2059 bytes
[eat this, Sucker !!!]
Recently I've been trying to write introductory manuals for some
of the languages we have available, and in the process of converting a
Modula-2 program to Pascal I found an (apparent) error in the definition
of the Pascal language (we have 4.2 BSD.)
It seems that the "read" statement will allow reading past the end
of the current line and on to the next. Isn't this wrong, (at least as
far as the way the read was supposed to work) ???
As an example, the following code will not operate correctly
(as I understand the idea of correctness):
program ReadTest(input,output);
var C: char;
begin
repeat
while not eoln do begin (* should echo one line of chars *)
read(C); write(C);
end;
readln(C); (* supposed to be required to read past *)
writeln; (* end-of-line marker, right ??? *)
until eof;
end.
This program seems to work fine when you are reading from the
standard input, but if you redirect input from a file, every other line
is skipped. Perhaps I'm full of blue mud, but I thought that you could
"read" forever without reading past the end of line. Can someone explain
either where my misconception of the language definition is, or maybe
verify that this is a legitimate bug ?
--
Russell Shilling
{ allegra, ihnp4, seismo }!scgvaxd!muddcs!russell
===== plplplplplplplplplplplplplplplplplp =====
Re: Bug in 4.2 BSD Pascal implementation ???
Author: Hans Albertsson
Date: Tue, 04 Sep 1984 11:32
Date: Tue, 04 Sep 1984 11:32
14 lines
970 bytes
970 bytes
[]
read(..); may indeed read past end of line; when actually reading
the eoln-marker, itv returns a blank in its argument. Readln is merely
a convenient way to skip to the next line without knowing how far
the next end-of-line is.
J&W is quite clear on this.
--
{decvax,philabs}!mcvax!enea!log-hb!hans
Hans Albertsson,
TeleLOGIC AB
Box 1001,
S-14901 Nynashamn,
SWEDEN
Re: Bug in 4.2 BSD Pascal implementation ???
Author: cdr
Date: Tue, 02 Oct 1984 20:57
Date: Tue, 02 Oct 1984 20:57
33 lines
2234 bytes
2234 bytes
I'm not on a 4.2 system, but from what I can see of your "bug",
it's not one.
It seems that job of read is not to keep you out of the control
characters but to only give you a printable char for whatever it was
that you did read, ie, a blank.
If you read past eoln and don't know it you'll get more than was
actually in the line. That's why you only want to read til eoln
so you don't get blanks when read is trying to keep you from getting
into control chars. As I understand Pascal, if you want to get past
eoln the classic way is "readln;" without any arguments. Whatever
readln doesn't have buffer space for in the vars that you give it,
it is supposed to just junk.
Likewise, if you're interested in reading the real chars in a line,
don't use read but just "get" from the file pointer.
Dont forget that the file pointer is always pointing to the char that
you're about to read. This would explain why it's "skipping a line".
What you've done is, with the read loop you got the file pointer on
the newline char, then with the "readln(C);" you got a blank
(substituted for the newline) in "C" and then readln did what it was
supposed to do after it loads the vars you've given it, it started
reading (and junking) characters til it found a newline. One of readln's
jobs is to always leave the file pointer on the first char afterthe
newline it found in it's search.
--
____________________________________________________________________________
Constantine Rasmussen (617) 657-8720 x2320
Pixel Computer Incorporated; 260 Fordham Road; Wilmington, Ma. 01887
{allegra|ihnp4|cbosgd|ima|genrad|amd|harvard} !wjh12!pixel!cdr
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads