ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (05/30/90)
In article <1751@tkou02.enet.dec.com>, diamond@tkou02.enet.dec.com (diamond@tkovoa) writes:
: >Um, I've recently had a lot more contact with people from a Pascal
: >background than I really wanted. Quickly now, what's wrong with this:
: 1> program main;
--------------------^ (output) should be declared because it is used!
: 2> var i: integer;
: 3> procedure p(n: integer);
: 4> begin
: 5> for i := 1 to n do write(' ');
------------------------^ the loop control variable must be LOCAL
: 6> writeln(i);
----------------------------^ the loop control variable is now UNDEFINED
: 7> end;
: 8> begin
: 9> p(10);
:10> end.
: >(I count three violations of the Pascal Standard.)
: Then read the Pascal Standard and count again. There is one violation.
Here are slightly edited error messages from a compiler:
Line 5: FOR-loop control variable must be declared at this level
Line 5: Standard file "output" must be declared by PROGRAM statement
Line 6: Must assign value before using variable
Line 6: Standard file "output" must be declared by PROGRAM statement
: (Did you think that Pascal lacks a null statement?)
No of course I didn't. I do hope that winning this argument helps to
convince people that I'm right about the superiority of for (;;) over
while (1) as well, but somehow I don't suppose it will. Too bad.
--
"A 7th class of programs, correct in every way, is believed to exist by a
few computer scientists. However, no example could be found to include here."
femto@ucscb.UCSC.EDU (71017000) (05/31/90)
I have used the following for several years: #define HELL 666 #define FROZEN -273 while (HELL != FROZEN) { ... do whatever -- Ken Woodruff -- femto@ucscb.ucsc.edu -- "As the world outside grows colder, I turn to my computer, -- and spend my evenings with it like a friend." -- Kate Bush
john@newave.UUCP (John A. Weeks III) (05/31/90)
In article <3104@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: >In article <1751@tkou02.enet.dec.com>, diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >: 1> program main; >--------------------^ (output) should be declared because it is used! >: >(I count three violations of the Pascal Standard.) This has very little to do with "C"--but there can still be a lesson in this. By far, the largest installed base of Pascal is Turbo Pascal. As a result, the standard has little to do with most Pascal code. There are also C programmers in this situation. One of the machines I write code for has no concept of a file, terminal, error handling, and it does not allow the programmer to define a "main" procedure. This kind of makes most of the "standard library" useless and the C code is quite unique to that machine. I sure hope my review is not based on my conformance to the "standard". -john- -- =============================================================================== John A. Weeks III (612) 942-6969 john@newave.mn.org NeWave Communications ...uunet!rosevax!bungia!wd0gol!newave!john ===============================================================================
e89hse@rigel.efd.lth.se (06/03/90)
In article <3928@darkstar.ucsc.edu>, femto@ucscb.UCSC.EDU (71017000) writes: > >I have used the following for several years: > >#define HELL 666 >#define FROZEN -273 > >while (HELL != FROZEN) { > ... do whatever I think it would be better to write something like: #if HELL != FROZEN for(;;) /* or while(1) if you prefer */ ... do whatever #endif This has the advatge that lint (at least some lints) won't warn you for unreachable code. I also think, but this is a personal opinion, that it is clearer. Henrik Sandell ps. Concerning while(1) and for(;;). My old CP/m C-compiler (Digital Research) used to have the declaration: #define forever() for(;;) in portab.h. I agree that for(;;) is ugly, but somehow I don't think while(1) look good either.