Recent

Author Topic: Lazarus in Windows allowed float types  (Read 543 times)

vinntec

  • New Member
  • *
  • Posts: 11
Lazarus in Windows allowed float types
« on: January 22, 2026, 11:59:08 am »
Coming from C and back to Pascal, I rewrote one of my complex programs (in Lazarus as it has an IDE) but managed to leave a few float variables and arrays in place by mistake. Rather than giving me an error when compiling, on Windows it turned these into Double - which was fine for my program.

Now I have moved my program to Linux (Zorin OS), this compiler treats float variables and arrays as Extended, which stops large chunks from compiling. It was easy to fix by changing the floats to doubles and recompiling.

However, the question is: Why didn't the compiler on either system flag my erroneous use of float as a syntax error? There is no such type and I can't find float anywhere in the documentation.

Lazarus 4.4 on both systems
« Last Edit: January 22, 2026, 12:04:25 pm by vinntec »

cdbc

  • Hero Member
  • *****
  • Posts: 2616
    • http://www.cdbc.dk
Re: Lazarus in Windows allowed float types
« Reply #1 on: January 22, 2026, 12:11:14 pm »
Hi
That depends on processor & OS....
An easy fix is to put the following in a shared unit, that all the other units with 'float' values can /see/:
Code: Pascal  [Select][+][-]
  1. type
  2.   Float = double;
This forces 'Float' to be an alias for the 'double' floating point datatype.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12116
  • Debugger - SynEdit - and more
    • wiki
Re: Lazarus in Windows allowed float types
« Reply #2 on: January 22, 2026, 12:17:05 pm »
However, the question is: Why didn't the compiler on either system flag my erroneous use of float as a syntax error?

Maybe you used the unit "Math" or any other unit that defines it?

From Math
Code: Pascal  [Select][+][-]
  1. {$if defined(FPC_HAS_TYPE_FLOAT128)}
  2.       type
  3.          Float = Float128;
  4. ...
  5. {$elseif defined(FPC_HAS_TYPE_EXTENDED)}
  6.       type
  7.          Float = extended;
  8. ...
  9. {$elseif defined(FPC_HAS_TYPE_DOUBLE)}
  10.       type
  11.          Float = double;
  12. ....
  13. {$elseif defined(FPC_HAS_TYPE_SINGLE)}
  14.       type
  15.          Float = single;
  16. ...
  17.  

speter

  • Sr. Member
  • ****
  • Posts: 487
Re: Lazarus in Windows allowed float types
« Reply #3 on: January 22, 2026, 12:25:39 pm »
Note also that you can generally right-click on a variable or type and get a context menu in the IDE, the first item on that menu is (something like) "show me where this is declared". I don't know the alternative way to invoke this (if you don't have a right mouse/trackpad button).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

tetrastes

  • Hero Member
  • *****
  • Posts: 739
Re: Lazarus in Windows allowed float types
« Reply #4 on: January 22, 2026, 12:31:49 pm »

LeP

  • Full Member
  • ***
  • Posts: 137
Re: Lazarus in Windows allowed float types
« Reply #5 on: January 22, 2026, 12:38:29 pm »
As far as I know, the float type doesn't exist in Pascal.
Something similar exists in Delphi, but the "size" must be explicitly specified: float32, float64.
The Float type probably comes from the bad (my personal thoughts) habit of importing the same type used in C into Pascal (or rather, FPC and Lazarus) to facilitate porting.
Always use the "double" or "single" types explicitly and forget about float.

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: Lazarus in Windows allowed float types
« Reply #6 on: January 22, 2026, 01:24:17 pm »
Even in C or its bastard cousins FLOAT is an alias. Just like it is in Pascal.
Is that so difficult to comprehend?????
Almost trolling. >:( >:D
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

vinntec

  • New Member
  • *
  • Posts: 11
Re: Lazarus in Windows allowed float types
« Reply #7 on: January 22, 2026, 01:31:37 pm »
In my case, it is including the Math unit which is the culprit, but which I needed for scientific calculations. I did try defining float as a type of double to make fixing quicker, but that made things worse (probably due to conflict with Math). Thanks everyone for the explanations - you learn something new every day

Khrys

  • Sr. Member
  • ****
  • Posts: 391
Re: Lazarus in Windows allowed float types
« Reply #8 on: January 22, 2026, 01:48:57 pm »
Even in C or its bastard cousins FLOAT is an alias.

ISO/IEC 9899, 6.2.5 Types (pages 45-49 in the PDF, the part where basic types such as  int  or  signed char  are defined) states:

Quote from: ISO/IEC 9899 6.2.5.10
There are three real floating types, designated as  floatdouble,  and  long
double
.  The set of values of the type  float  is a subset of the set of values of the type
double;  the set of values of the type  double  is a subset of the set of values of the
type  long double.

LeP

  • Full Member
  • ***
  • Posts: 137
Re: Lazarus in Windows allowed float types
« Reply #9 on: January 22, 2026, 02:53:24 pm »
.... FLOAT is an alias[/u]. Just like it is in Pascal.
In Pascal there is no FLOAT type used commonly, only FPC use (may be) this alias ... not PASCAL.

And since it doesn't have a univocal definition, it would be better not to use it. But obviously, this is my humble opinion.

vinntec

  • New Member
  • *
  • Posts: 11
Re: Lazarus in Windows allowed float types
« Reply #10 on: January 22, 2026, 06:01:29 pm »
@LeP As I said at the start, I didn't mean to use float, but just got carried away in a few places where I forgot to change the "float" in the C code into "single" or "double" in Pascal. It turns out that using the Math unit on Windows, FPC treats float as a Double, but on Linux as an Extended. So it only showed up as a problem on Linux.

 

TinyPortal © 2005-2018