[fpc-devel]Determining overloads between Single and Double

Michalis Kamburelis michalis at camelot.homedns.org
Fri Feb 13 22:17:21 CET 2004


Hi.

This question is related to bugs 2854, 2885 and 2971 that I submitted. 
To state this shortly: how should I change code

   {$mode DELPHI}

   procedure p(const b:Single); overload;
   begin end;

   procedure p(const b:Double); overload;
   begin end;

   begin p(1.0) end.

to make it compile with latest FPC version (1.9.3) ? I.e., without 
removing {$mode DELPHI} ?

Answer to bug 2885 states that FPC cannot determine which overload to 
call automatically (like Delphi does) because of portability. So my 
solution in FPC 1.0.x was to use Single(1.0), i.e.
   begin p(Single(1.0)) end;
worked.

Unfortunately, under Delphi writing "Single(1.0)" is not allowed and 
behavior of newer FPC (1.9.x) was changed to be compatible with this 
(i.e. to NOT compile "Single(1.0)" under Delphi mode). Answers to bugs 
2854 and 2971 state that.

So how should I change that code to make it compile (without adding too 
much code, i.e. I know I could write

   const c:Single = 1.0;
   begin p(c) end.

and that works but it's definitely not a short solution for such small 
problem).

 From my point of view I am happy that FPC cares about portability and 
so I accept that some things just cannot be done like in Delphi. So I 
understand that FPC can't determine which overload to call when I use 
p(1.0). I would be perfectly happy with using p(Single(1.0)).

I don't think it's useful when FPC doesn't compile some code just 
because Delphi doesn't compile it too. I would rather like to see that 
Delphi mode is something "compatible" with Delphi in the sense that "In 
Delphi mode we're trying hard to compile everything that Delphi can 
compile BUT we also allow some FPC specific things that do not conflict 
with Delphi mode (like Single(1.0))".

Once I thought that "ObjFpc" mode was meant to be that. But it is not,
at some places it changes syntax in incompatible way. I like some ideas 
specific to ObjFpc mode (e.g. I like the security check in ObjFpc not 
allowing me to write
   .. = class
     X:Integer;
     procedure P(X:Integer)
   end
) but sometimes it's a pain trying to write code in ObjFpc mode that 
should compile under Delphi too (e.g. when assigning procedural 
variables - sometimes in Delphi (and FPC's Delphi mode) I can't use @ 
char and in ObjFpc I have to use it). So I like FPC features' set very 
much but neither ObjFpc mode nor Delphi mode have all that I want.

Regards,
Michalis




More information about the fpc-devel mailing list