Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Jonas Maebe

On 27 May 2010, at 23:31, Yann Bat wrote:

>> The compiler always adds a VMT if an object has a constructor or destructor. 
>> The reason is that the VMT also contains the instance size, which is used by 
>> the constructor helper to allocate the required amount of memory.
> 
> Ok but why a different behaviour between [fpc | objfpc] mode and [tp |
> delphi] mode ?

It is allowed in Delphi and TP because they allow declaring typed constants of 
objects. I don't remember why it was disabled in the FPC modes, but that 
happened a long time ago (before the move from cvs to svn). Maybe someone else 
does.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Yann Bat
> The compiler always adds a VMT if an object has a constructor or destructor. 
> The reason is that the VMT also contains the instance size, which is used by 
> the constructor helper to allocate the required amount of memory.
>

Ok but why a different behaviour between [fpc | objfpc] mode and [tp |
delphi] mode ?
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Jonas Maebe

On 27 May 2010, at 16:01, Yann Bat wrote:

> I don't understand why compilation of the program below failed in fpc
> and objfpc mode. In tp and delphi mode it works as expected but in fpc
> and objfpc mode the compiler complains :
> 
>  blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed
>  blob.pas(17,3) Fatal: Syntax error, ";" expected but "(" found
> 
> Since my object has no virtual methods why a VMT ?

The compiler always adds a VMT if an object has a constructor or destructor. 
The reason is that the VMT also contains the instance size, which is used by 
the constructor helper to allocate the required amount of memory.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Jonas Maebe

On 27 May 2010, at 21:51, Flávio Etrusco wrote:

> On Thu, May 27, 2010 at 11:01 AM, Yann Bat  wrote:
>> type
>>  TBlob = object
>>private
>>  fId : LongInt;
>> 
>>public
>>  constructor Init;
>>  function Id: LongInt;
>>  end;
>> 
>>  PBlob=^TBlob;
>> 
>> const
>>  NullBlob : TBlob = (fId: 0);
>> 
>> {=== TBlob ===}
>> constructor TBlob.Init;
>> begin
>>  fId:=Random(1024) + 1;
>> end;
>> 
> 
> All TObject descendants have a VMT.

The above is not a TObject descendant. It's a TP-style object.


Jonas___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Flávio Etrusco
All TObject descendants have a VMT. The destructor is virtual, BTW.

-Flávio

On Thu, May 27, 2010 at 11:01 AM, Yann Bat  wrote:
> Hi,
>
> I don't understand why compilation of the program below failed in fpc
> and objfpc mode. In tp and delphi mode it works as expected but in fpc
> and objfpc mode the compiler complains :
>
>  blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed
>  blob.pas(17,3) Fatal: Syntax error, ";" expected but "(" found
>
> Since my object has no virtual methods why a VMT ?
>
> Thanks.
>
>
> {$mode fpc}
> program Blob;
>
> type
>  TBlob = object
>    private
>      fId : LongInt;
>
>    public
>      constructor Init;
>      function Id: LongInt;
>  end;
>
>  PBlob=^TBlob;
>
> const
>  NullBlob : TBlob = (fId: 0);
>
> {=== TBlob ===}
> constructor TBlob.Init;
> begin
>  fId:=Random(1024) + 1;
> end;
>
> function TBlob.Id;
> begin
>  Id:=fId;
> end;
>
> var
>  B : TBlob;
> begin
>  B:=NullBlob;
>  WriteLn('B : ', B.Id);
>
>  B.Init;
>  WriteLn('B : ', B.Id);
> end.
> ___
> fpc-pascal maillist  -  fpc-pas...@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] FPC bug or brain bug ?

2010-05-27 Thread Yann Bat
Hi,

I don't understand why compilation of the program below failed in fpc
and objfpc mode. In tp and delphi mode it works as expected but in fpc
and objfpc mode the compiler complains :

  blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed
  blob.pas(17,3) Fatal: Syntax error, ";" expected but "(" found

Since my object has no virtual methods why a VMT ?

Thanks.


{$mode fpc}
program Blob;

type
  TBlob = object
private
  fId : LongInt;

public
  constructor Init;
  function Id: LongInt;
  end;

  PBlob=^TBlob;

const
  NullBlob : TBlob = (fId: 0);

{=== TBlob ===}
constructor TBlob.Init;
begin
  fId:=Random(1024) + 1;
end;

function TBlob.Id;
begin
  Id:=fId;
end;

var
  B : TBlob;
begin
  B:=NullBlob;
  WriteLn('B : ', B.Id);

  B.Init;
  WriteLn('B : ', B.Id);
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] $CODEALIGN / Dynamic Arrays

2010-05-27 Thread Jonas Maebe


On 27 May 2010, at 09:47, Helmut Hartl wrote:

Does the $CODEALIGN (http://www.freepascal.org/docs-html/prog/progsu9.html 
)

directive influence dynamic array memory layout ?


No, that directive only influences static code and data layout.

I need an an aligned dynamic array of vectors for SSE operations. If  
the
fpc dynamic array implementation supports alignment somehow I would  
not

need an own implementation of an allocator.


It doesn't support that. The proper way to support it would be to add  
some kind of vector data type to the compiler, whose rtti would  
indicate the alignment requirements (so the dynamic array allocation  
would take care of the alignment automatically).



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] $CODEALIGN / Dynamic Arrays

2010-05-27 Thread Helmut Hartl

Does the $CODEALIGN (http://www.freepascal.org/docs-html/prog/progsu9.html)
directive influence dynamic array memory layout ?

I need an an aligned dynamic array of vectors for SSE operations. If the
fpc dynamic array implementation supports alignment somehow I would not
need an own implementation of an allocator.

Any thoughts ?

thanks,
  helmut
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal