tobjsize.pp 993 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. type
  2. pbaseclass = ^tbaseclass;
  3. pderivedclass = ^tderivedclass;
  4. tbaseclass = object
  5. x : longint;
  6. constructor init;
  7. destructor done; virtual;
  8. end;
  9. tderivedclass = object(tbaseclass)
  10. y : longint;
  11. end;
  12. const
  13. has_error : boolean = false;
  14. expected_size_for_tbaseclass = sizeof(pointer) + sizeof(longint);
  15. expected_size_for_tderivedclass = sizeof(pointer) + 2*sizeof(longint);
  16. var
  17. basesize : longint;
  18. derivedsize : longint;
  19. constructor tbaseclass.init;
  20. begin
  21. end;
  22. destructor tbaseclass.done;
  23. begin
  24. end;
  25. var
  26. cb : tbaseclass;
  27. cd : tderivedclass;
  28. begin
  29. cb.init;
  30. cd.init;
  31. basesize:=sizeof(cb);
  32. Writeln('Sizeof(cb)=',basesize);
  33. if basesize<>expected_size_for_tbaseclass then
  34. Writeln('not the expected size : ',expected_size_for_tbaseclass);
  35. derivedsize:=sizeof(cd);
  36. Writeln('Sizeof(ct)=',derivedsize);
  37. if derivedsize<>expected_size_for_tderivedclass then
  38. Writeln('not the expected size : ',expected_size_for_tderivedclass);
  39. end.