On Fri, Dec 06, 2002 at 10:21:50PM -0500, CBFalconer wrote:
I ran the following little tests. There are some comments in the source. In particular I am worrying about the use of field width specifications. 0 is illegal in ISO7185, legal in 10206. -ve are illegal in both, and not detected. I really have no great objections to this, but if it is not detected lets at least put it to good use. I recommend using -ve values to cause left justification in the field.
As usual: negative field width is an "error", which means:
3.2 Error
A violation by a program of the requirements of this International Standard that a processor is permitted to leave undetected.
There are dozens of other errors like this which gpc doesn't detect.
I also consider the failure to stop compilation on the final '.' a serious fault. This feature makes the sources immune to the lack of line termination at the end of the source file, and allows appending useful commentary there. Some of my files end with ^Z (for EOF on CP/M or MsDos) and a two byte CCIT CRC checksum. This makes it extremely easy to detect corruption. Heeding the final '.' makes the system immune to the OS handling of EOF markers.
The standard doesn't permit garbage anywhere, be it at the end of the file or at other place. (The "final ." actually doesn't have to be final, it may be followed by another module for example, and the compiler can't reliable distinguish a start of module declaration from your useful commentary or CRC checksum.) IIRIC gpc _does_ ignore stuff after the first final "." in --borland-pascal mode, but I don't remember if there a separate switch for this feature.
BTW what is the effect, if any, of the -pedantic, -W, -Wall gcc options? Should we be using -gstabs+ (my practice) or just -g. Under DJGPP in particular.
PROGRAM misctests(input, output); (* Compiled with --standard-pascal *)
CONST maxi = 32767; mini = -32768; maxwd = 65535;
TYPE integer = mini .. maxi; word16 = 0 .. maxwd;
VAR ch : char; i, j : integer;
BEGIN (* misctests *) writeln('Hello, World'); writeln('"', 'string in field of 25' : 25, '"'); writeln( '"1234567890123456789012345"'); writeln('Maxint = ', maxint : 0); writeln('Maxi = ', maxi : -20, ' Mini = ', mini : 1); (* disappointing that -ve field neither left justifies *) (* nor is flagged as an error *) (* My pref: 0 default, -ve for left just, +ve as usual *)
writeln('Enter lines until eof'); WHILE NOT eof DO IF eoln THEN BEGIN writeln; write(input^, 'Enter: new line: ' : 6); (* This ^ should be a blank *) (* Check truncates *) readln; END ELSE BEGIN output^ := input^; put(output); get(input); END;
writeln('Fld ActualFld'); writeln('=== ======...'); FOR i := -8 TO 8 DO writeln(i : 3, '"', maxi : i, '"');
i := maxi - 4; (* FOR j := maxi - 3 TO maxi + 3 DO BEGIN *) (* now throws a constant out of range error gpc321 *) (* which is definite progress towards range checks *) FOR j := -3 TO +3 DO BEGIN i := succ(i); write(i : 6); (* should crash *) END; writeln; writeln(' Should have crashed here after 32767'); END. (* misctests *) (* ^ Nothing should count after this period *) (* However gpc throws errors down here *) (* unless commented out *)
-- Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net) Available for consulting/temporary embedded and systems. http://cbfalconer.home.att.net USE worldnet address!