Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2004-02

Determining overloads between Single and Double

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michalis Kamburelis

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

Reply by email

Jonas Maebe
to Michalis Kamburelis
Michalis Kamburelis wrote
but sometimes it's a pain trying to write code in ObjFpc mode that should compile under Delphi too

In that case, why do you want to use that single(1.0) construct? That won't compile in Delphi either... I'm not sure what you are trying to achieve: writing code that "mostly" compiles under Delphi too? What's the use?

Jonas

Reply by email

Michalis Kamburelis
to Jonas Maebe
Jonas Maebe wrote 15 lines
On 13 feb 2004, at 22:17, Michalis Kamburelis wrote: > but sometimes it's a pain trying to write code in ObjFpc mode that > should compile under Delphi too In that case, why do you want to use that single(1.0) construct? That won't compile in Delphi either... I'm not sure what you are trying to achieve: writing code that "mostly" compiles under Delphi too? What's the use? Jonas

I don't *want* to use p(Single(1.0)) construct in that sense that I would be happy with using just p(1.0), too. My point was that in FPC in Delphi mode I can't use p(1.0) and I can't use p(Single(1.0)) too.

Regards,
Michalis

Reply by email

Peter Vreman
to Michalis Kamburelis
Show quoted text 19 lines
Jonas Maebe wrote: > > On 13 feb 2004, at 22:17, Michalis Kamburelis wrote: > >> but sometimes it's a pain trying to write code in ObjFpc mode that >> should compile under Delphi too > > > In that case, why do you want to use that single(1.0) construct? That > won't compile in Delphi either... I'm not sure what you are trying to > achieve: writing code that "mostly" compiles under Delphi too? What's > the use? > > > Jonas > I don't *want* to use p(Single(1.0)) construct in that sense that I would be happy with using just p(1.0), too. My point was that in FPC in Delphi mode I can't use p(1.0) and I can't use p(Single(1.0)) too.

Add a new overload for extended and it compiles also in delphi mode.

Bug report 2129 is the source that single(1.0) typecasts does not work as expected. A solution can be to do conversion for float constants.

Reply by email

Peter Vreman
to Peter Vreman
Show quoted text 6 lines
> Delphi mode I can't use p(1.0) and I can't use p(Single(1.0)) too. Add a new overload for extended and it compiles also in delphi mode. Bug report 2129 is the source that single(1.0) typecasts does not work as expected. A solution can be to do conversion for float constants.

Conversion is now done for float constants. Hope that solves the problem

Reply by email

Michalis Kamburelis
to Peter Vreman
Peter Vreman wrote
Conversion is now done for float constants. Hope that solves the problem

Just updated from CVS, I see it's in defcmp.pas. Now Single(1.0) is allowed. That's what I wanted. Great! Thanks.

Michalis

Reply by email