[fpc-devel] Parameters must match exactly?

Florian Klaempfl florian at freepascal.org
Tue May 18 10:10:39 CEST 2010

Vinzent Höfler schrieb:
> Florian Klaempfl <florian at freepascal.org>:
>> Vinzent Höfler schrieb:
>>> Florian Klaempfl <florian at freepascal.org>:
>>>> Graeme Geldenhuys schrieb:
>>>>> This compiler change will play havoc on the Simple Factory
>>>>> Method
>> design
>>>>> pattern as well - a base class is used as the parameter type,
>>>>> but descendants are created and passed back. This is a very
>>>>> common case
>> and
>>>>> used a lot.
>>>> ... and one uses normally a function and not a var/out
>>>> parameter.
>>> And return the error code in an out parameter instead? Great
>>> idea. So
>> readable. So much in the spirit of Pascal.
>> Doing/allowing unsafe implicit type casts is neither in the spirit
>> of pascal.
> You wouldn't *need* typecasts. It's a pointer and the instance it is
> pointing to will be initialized by the subroutine you're calling. And
> that one *knows* the size of the class it created. So there's
> typecast involved at all, if used correctly.

You even didn't get the problem :) I'll try again but I fear it's a
waste of time. Before the change, code like

{$mode objfpc}
  tc1 = class

  tc2 = class(tc1)

  tc3 = class(tc1)

procedure p(var c : tc1);

  c3 : tc3;


was allowed and this code is simply broken, the compiler has to complain
and this was fixed. Code depending on this lazy behaviour simply needs
to be fixed, there are several solutions like inserting a explicit type
cast or using functions maybe together with the as operator.

> And stop calling me clueless, please. 

You started to get personally rude so unfortunatly I think you've to
accept the same.

> Just because you do not
> understand what I write, doesn't exactly mean, I am the one who has
> no clue.

Oh really? You want to allow the code above? You call this pascalish?

More information about the fpc-devel mailing list