SizeOf with Objects BUG_(re)

Fri, 25 Jul 1997 02:04:27 +0200



Bernhard Tschirren wrote:

> You cannot use SizeOf with objects?!?! It just does not work. It either
> aborts during compilation, or it returns rediculous values during execution.

Did you initialize the object with a constructor call?

BTW: There is a little difference to BP: In BP, objects that have neither
constructors, destructors nor virtual methods don't have a VMT link.
So it's possible in BP to get their size without initalizing them.
I think that's kind of a misfeature, since the following program produces
the wrong result for vy in BP, so IMHO, BP's behaviour should not be
duplicated by gpc. (Though it's not 100% BP compatible then, a good BP
program shouldn't make use of it, anyway.)

type
  x=object
     a:integer;
    end;

  y=object(x)
     b:integer;
    end;

procedure w(var p:x);
begin
 writeln(sizeof(p))
end;

var
 vx:x;
 vy:y;

begin
 w(vx);
 w(vy);
end.
-- 
Frank Heckenbach, Erlangen, Germany
heckenb@mi.uni-erlangen.de
http://www.mi.uni-erlangen.de/~heckenb/links.htm


Frank Heckenbach (heckenb@mi.uni-erlangen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es