[fpc-devel] Bug in FPC and declaring distinct types

Martin Friebe fpc at mfriebe.de
Thu Sep 18 15:55:24 CEST 2008


Florian Klaempfl wrote:
> Yury Sidorov schrieb:
>>> Yury Sidorov schrieb:
>>>>>> Yes. But it works only partially. For example the following code 
>>>>>> is not compilable:
>>>>> Well, I wouldn't know either what you expect :)
>>>> I expect that compiler will choose DoTest with ansistring parameter 
>>>> in that case.
>>> What rule do you apply to say this?
>> Compiler treats '1234' as ansistring constant. Therefore ansistring 
>> overload must be choosen here.
> No, '1234' is taken as generic string constant.
I was able (with "Free Pascal Compiler version 2.2.2rc1 [2008/06/27] for 
i386") to compile the below.
(I know it's an old fpc version, but I am not at my home PC)

As shown with the non-overloaded procedures p1a, p1w, p1s: the string 
'xx' can be given to any of them.
On the other hand the compiler allowed me to overload p1 for short, ansi 
and wide-sring

I do not know which rule it followes if p1('xx') is called?

type
  sstr = String[3];
 
  procedure p1s (s : sstr);
  procedure p1a (s : ansistring);
  procedure p1w (s : widestring);

  procedure p1 (s : sstr); overload;
  procedure p1 (s : ansistring); overload;
  procedure p1 (s : widestring); overload;

implementation

procedure main;
begin
 p1('xx');
 p1s('xx');
 p1a('xx');
 p1w('xx');
end;


Warning: Use of ppc386.cfg is deprecated, please use fpc.cfg instead
Hint: Start of reading config file 
c:\lazarus\fpc\2.2.2\bin\i386-win32\fpc.cfg
Hint: End of reading config file c:\lazarus\fpc\2.2.2\bin\i386-win32\fpc.cfg
Warning: You are using the obsolete switch -OG
Free Pascal Compiler version 2.2.2rc1 [2008/06/27] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Win32 for i386
Compiling C:\DOCUME~1\Martin\LOCALS~1\Temp\project1.lpr
Compiling unit1.pas
unit1.pas(23,18) Hint: Parameter "s" not used
unit1.pas(24,18) Hint: Parameter "s" not used
unit1.pas(25,18) Hint: Parameter "s" not used
unit1.pas(27,17) Hint: Parameter "s" not used
unit1.pas(28,17) Hint: Parameter "s" not used
unit1.pas(29,17) Hint: Parameter "s" not used
Linking C:\DOCUME~1\Martin\LOCALS~1\Temp\project1.exe
101 lines compiled, 1.3 sec , 1056816 bytes code, 280748 bytes data
2 warning(s) issued
8 hint(s) issued
Project "project1" successfully built. :)



>
>>
>> Like in this case:
>>
>> const
>>  sss: ansistring = '1234';
>> ...
>> DoTest(sss);
>>
>>>>>> //------
>>>>>> type
>>>>>>  TUTF8String = type ansistring;
>>>>>>
>>>>>> procedure DoTest(const s: ansistring); overload;
>>>>>> begin
>>>>>> end;
>>>>>>
>>>>>> procedure DoTest(const s: TUTF8String); overload;
>>>>>> begin
>>>>>> end;
>>>>>>
>>>>>> begin
>>>>>>  DoTest('1234');
>>>>>> end.
>>>>>>
>>>>>> //------
>> _______________________________________________
>> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
>> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel



More information about the fpc-devel mailing list