[fpc-devel] Unicode and UTF8String

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Dec 1 22:45:33 CET 2008


On 01 Dec 2008, at 22:33, Martin Friebe wrote:

> I suggested to have a rtl, that has overloaded functions for each  
> string type.
> of course that sounds easier than in fact it will be.
>
> Florian pointed out a few issues, like overloading by result is not  
> possible (yet?).

No, it is fundamentally impossible. First of all, because a Pascal  
compiler does not look at how the result of an expression is used  
while parsing the expression (so while evaluating a function call, the  
compiler has no idea what the "expected" result type is). That's  
simply how Pascal works.

And how could the compiler decide what to call here:

function f: longint;
begin
   result:=1;
end;

function f: string;
begin
   result:='s';
end;

begin
   writeln(f);
end.

There are an immense amount of similar examples possible (and if you  
add operator overloading in the mix, it increases exponentially), and  
you'd get a huge amount of "can't decide which overloaded function to  
call" errors even if the compiler were hacked to take the use of the  
function results into account.


Jonas



More information about the fpc-devel mailing list