Prof A Olowofoyeku (The African Chief) wrote:
So, I guess that the first statement means that a constructor is expected when there are virtual methods. The penultimate statement also seems to indicate that a constructor is treated as something special by the BP compiler (and therefore probably involves some special processing),
I think so, so the warning seems justified for any dialect.
whereas I don't believe that this is necessarily the case under GPC. How/where does GPC achieve it's "setting the link between the object and the virtual method table with addresses of the code for its virtual methods"?
When the object starts to exist, i.e. for global or static ones in the program/unit/module constructor, for (non-static) local ones at the start of the routine, and for dynamic ones immediately after the memory allocation (whether or not a constructor is given in `New').
PS: I know that, under BP and Delphi, a call to the constructor automatically zeroes out all the object's fields as appropriate (e.g., pointers are set to Nil, numbers are set to zero, and strings are set to empty).
Nope. The following gives 1 under BP (2 under GPC). I don't know what Delphi does, but BP certainly doesn't. I think it's the same issue as with global variables (and also non-objects allocated from the heap). Sooner or later one has to learn that unintialized variables and fields are undefined in Pascal, even though GPC (at least on most platforms, perhaps all) zeroes global variables at program start.
program Foo;
type t = record a, b, c: Integer end;
o = object a: Integer; constructor Init; end;
constructor o.Init; begin end;
var p: ^t; q: ^o;
begin New (p); p^.a := 1; p^.b := 2; p^.c := 3; Dispose (p); New (q, Init); WriteLn (q^.a) end.
Frank