What Warnings are supposed to work right now? I have the impression that -Wall, -pedantic do have not much effect.
E.g. detecting uninitialized variables seems to be a problem (did not work too when using -O, -O2..)
Regards, Marc
Marc van Woerkom wrote:
What Warnings are supposed to work right now? I have the impression that -Wall, -pedantic do have not much effect.
Huh? When I am trying to compile anything beyond "Hello, world" with `-pedantic', I get big piles of warnings. Maybe your programming style is just ultra-safe?
`-pedantic' gives warnings about every possible incompatibility with any Pascal compiler we know about, leaving not much room for programming.
`-Wall' is simply inherited from GCC and does suggestions about `begin ... end' blocks etc. IMHO, this is not very important in Pascal.
E.g. detecting uninitialized variables seems to be a problem (did not work too when using -O, -O2..)
This is indeed only detected when the compiler is tracking each variable carefully enough - which is the case only with optimization. BTW, global variables are never considered uninitialized because they are initialized to zero (or Nil or false or empty string or ...) at the beginning of the program. This is (a) inherited from GCC and (b) for compatibility to Borland Pascal. An option to turn this off would be useful but too much work for now.
Hope this helps somehow ...
Peter
Huh? When I am trying to compile anything beyond "Hello, world" with `-pedantic', I get big piles of warnings. Maybe your programming style is just ultra-safe?
Nope, I make mistakes like everyone else.
It is rather that my examples are too simple or maybe that I used gpc with old faithful gcc-2.8.1 so far.
Getting used a bit to gpc now, I will try to integrate and compile it with
gcc version 2.96 19991110 (experimental)
from the FreeBSD ports collection
This is indeed only detected when the compiler is tracking each variable carefully enough - which is the case only with optimization. BTW, global variables are never considered uninitialized because they are initialized to zero (or Nil or false or empty string or ...) at the beginning of the program.
I have no problems with it, as a TP and C++ vet, but the Pascal purists do ..
When I used gpc for a problem in a programming course recently, I got some points deducted, because of an unitialized variable (FeldMax in the example below), the use of the 'ö' Umlaut in the comment at the beginning and (this gpc is not supposed to check :) the waste of an array for determing the maximum.
program Maximum(input, output); { Lösung zur Aufgabe 1, Ü2 KIP } const IMAX = 32000;
type tIndex = 1..IMAX; tIndex0 = 0..IMAX; tFeld = array[tIndex] of integer;
var i : tIndex0; Feld : tFeld; FeldMax : integer;
begin { Eingabe der Folge und Bestimmung des Maximums } i := 0;
repeat i := succ(i);
write('Wert für feld[', i, ']? '); readln(Feld[i]); writeln;
if (Feld[i] <> 0) then if (i = 1) or (Feld[i] > FeldMax) then FeldMax := Feld[i];
until Feld[i] = 0;
{ Ausgabe des Maximums } if i = 1 then writeln('Leere Eingabefolge!') else writeln('Das Maximum ist: ', FeldMax)
end. { Maximum }
.. so I would like gpc to be made nitpicking for this case.
This is what I get during compilation:
marc@oranje$ gpc -v Reading specs from /usr/ports/lang/gpc/inst2/lib/gcc-lib/i386-unknown-freebsd4.0/2.8.1/specs gpc version 19991030, based on gcc-2.8.1 marc@oranje$ gpc -pedantic u2a1.pas marc@oranje$ gpc -pedantic -O2 u2a1.pas marc@oranje$ gpc -Wall -pedantic -O2 u2a1.pas u2a1.pas:39: warning: third argument of `main' is deprecated marc@oranje$
The general impression of gpc is not perfect, but already very useful. Thanks for your work!
Regards, Marc