Re: fpc 2.3.1 doesn't allow to pass literal constants as formal const parameter

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: fpc 2.3.1 doesn't allow to pass literal constants as formal const parameter

Peter Vreman
> Currently fpc 2.3.1 cannot build lazarus anymore. It fails on lines like
> MyStream.Write(' ',1);
>
> The write method is declared as
>    function Write(const Buffer; Count: Longint): Longint
>
> Why isn't passing literal constant to a formal const parameter allowed
> anymore?

1. It is passed by value and not by reference.
2. You don't know the size of the value.
3. It is delphi compatible

Peter

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpc 2.3.1 doesn't allow to pass literal constants as formal const parameter

Vincent Snijders
Peter Vreman schreef:
>> Currently fpc 2.3.1 cannot build lazarus anymore. It fails on lines like
>> MyStream.Write(' ',1);
>>
>> The write method is declared as
>>    function Write(const Buffer; Count: Longint): Longint
>>
>> Why isn't passing literal constant to a formal const parameter allowed
>> anymore?
>

I see this change is intentional, but I don't understand it completely yet.

> 1. It is passed by value and not by reference.

The compile could decide to pass by reference, couldn't it.

> 2. You don't know the size of the value.

The caller knows the size, doesn't it. Why do you need to know the size?

> 3. It is delphi compatible
>

At last, one reason I understand :-).

Thanks,
Vincent
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: fpc 2.3.1 doesn't allow to pass literal constants as formal const parameter

Jonas Maebe-2

On 06 Mar 2008, at 22:22, Vincent Snijders wrote:

> Peter Vreman schreef:
>>
>> 1. It is passed by value and not by reference.
>
> The compile could decide to pass by reference, couldn't it.

That's what it did in the past, but that's a hack (because it's  
passing a value without an address by reference).

>> 2. You don't know the size of the value.
>
> The caller knows the size, doesn't it.

No, it doesn't. Ordinal constants have no inherent size in Pascal  
(well, in case of TP/Delphi and therefore FPC: most of the time, at  
least).

> Why do you need to know the size?

E.g. on big endian, the memory layout of byte(1), word(1), cardinal(1)  
and qword(1) is completely different.


Jonas
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal