Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-03

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

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter Vreman
Show quoted text 8 lines
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

Vincent Snijders
to Peter Vreman
Peter Vreman wrote 9 lines
> 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

Jonas Maebe
to Vincent Snijders
Vincent Snijders wrote 5 lines
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