[fpc-pascal] Weird string behavior

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Jul 26 16:26:01 CEST 2016

Santiago A. wrote on Tue, 26 Jul 2016:

> El 26/07/2016 a las 12:27, Mattias Gaertner escribió:
>> a3:=a1+a2 => cp = 1252
>> a3:=a2+a1 => cp = 65001
> Is that the expected behavior?
> IMHO the result should be the same. And the only way is to make it
> depend on a3, no matter what is in the left side. That's the way things
> are done in Pascal

String concatenations are not commutative operations, even if no code  
pages are involved (even in Pascal). I think it is logical that the  
code page of the left operand is kept, because it is the "base string"  
to which you add other data.

The fact that the concatenated data is not converted in this scenario  
makes some sense in the context of the "same declared code page -> no  
conversion" rule that is also used for assignments, but it's something  
I'm less happy about. Maintaining multiple helpers, compiler  
behaviours and documentation is even less enticing though, so I will  
implement the Delphi behaviour. It will also slightly speed up string  
concatenations when all strings have the same declared code page,  
because no checks need to be performed at run time regarding whether  
or not data needs to be converted.


More information about the fpc-pascal mailing list