Sign in Join

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

Mailing lists / fpc-devel / 2022-11

Just need to double check the size of Integer

17 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

J. Gareth Moreton

Hi everyone,

I just need to double-check something.  Under CPU16, SizeInt and SizeUInt are declared as follows:

   SizeInt = Integer;
   SizeUInt = Word;

Is Integer 16-bit in this case? I always thought Integer was defined as a signed 32-bit integer under FreePascal.  Or is this a bug with rtl/inc/systemh.inc and it should be defined as SmallInt instead?

Kit

Reply by email

Marco van de Voort
to J. Gareth Moreton
J. Gareth Moreton wrote 8 lines
I just need to double-check something.  Under CPU16, SizeInt and SizeUInt are declared as follows:   SizeInt = Integer;   SizeUInt = Word; Is Integer 16-bit in this case?

Yes.

I always thought Integer was defined as a signed 32-bit integer under FreePascal.

No. Only in objfpc/delphi modes, and system is in $mode FPC. Unit objpas overrides this definition and is loaded in objfpc/delphi mode.

begin
writeln(sizeof(integer));
end.

without any $mode (so $mode fpc) will write 2, even on 64-bit systems.

Reply by email

Tomas Hajny
to J. Gareth Moreton: I just need to double-check something.  Under CPU16, SizeInt and SizeUInt are declared…

On 2022-11-24 14:13, J. Gareth Moreton via fpc-devel wrote:

Hi Kit,

Show quoted text 9 lines
I just need to double-check something.  Under CPU16, SizeInt and SizeUInt are declared as follows:   SizeInt = Integer;   SizeUInt = Word; Is Integer 16-bit in this case? I always thought Integer was defined as a signed 32-bit integer under FreePascal.  Or is this a bug with rtl/inc/systemh.inc and it should be defined as SmallInt instead?

You're wrong. The size of Integer depends on the compilation mode. It is 16-bit in the TP and FPC modes, but overridden to 32-bit in OBJPAS and DELPHI modes.

Tomas

Reply by email

Ondrej Pokorny
to Marco van de Voort: Yes. No. Only in objfpc/delphi modes, and system is in $mode FPC. Unit objpas overrides…
Marco van de Voort wrote 11 lines
On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: > > I just need to double-check something.  Under CPU16, SizeInt and > SizeUInt are declared as follows: > >   SizeInt = Integer; >   SizeUInt = Word; > > Is Integer 16-bit in this case? Yes.

Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer within the system unit is 32-bit.

So to me it looks like a bug.

Documentation:
https://www.freepascal.org/docs-html/ref/refsu4.html https://www.freepascal.org/docs-html/rtl/system/sizeint.html

Ondrej

Reply by email

Ondrej Pokorny
to Marco van de Voort: Yes. No. Only in objfpc/delphi modes, and system is in $mode FPC. Unit objpas overrides…
Marco van de Voort wrote 18 lines
On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: > > I just need to double-check something.  Under CPU16, SizeInt and > SizeUInt are declared as follows: > >   SizeInt = Integer; >   SizeUInt = Word; > > Is Integer 16-bit in this case? Yes. > I always thought Integer was defined as a signed 32-bit integer under > FreePascal. No. Only in objfpc/delphi modes, and system is in $mode FPC. Unit objpas overrides this definition and is loaded in objfpc/delphi mode.

OK, I found it. Actually within the system unit Integer is always 16-bit because it is re-declared on line 114:
Integer  = SmallInt;

So yes, Integer in the system unit is 16-bit but because of the re-declaration and not the mode.

Ondrej

Reply by email

J. Gareth Moreton
to Ondrej Pokorny: Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer…

Hence why I wanted to double-check!  Normally if I want something to be an particular size, I use "ShortInt", "SmallInt" and "LongInt" etc. to ensure there is no ambiguity.

Kit

Ondrej Pokorny wrote 28 lines
Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: > On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >> >> I just need to double-check something.  Under CPU16, SizeInt and >> SizeUInt are declared as follows: >> >>   SizeInt = Integer; >>   SizeUInt = Word; >> >> Is Integer 16-bit in this case? > > Yes. Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer within the system unit is 32-bit. So to me it looks like a bug. Documentation: https://www.freepascal.org/docs-html/ref/refsu4.html https://www.freepascal.org/docs-html/rtl/system/sizeint.html Ondrej _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Marco van de Voort
to Ondrej Pokorny: Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer…
Ondrej Pokorny wrote 15 lines
Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: > On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >> >> I just need to double-check something.  Under CPU16, SizeInt and >> SizeUInt are declared as follows: >> >>   SizeInt = Integer; >>   SizeUInt = Word; >> >> Is Integer 16-bit in this case? > > Yes. Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer within the system unit is 32-bit.

1. Then why does the posted code print 2?

2. using {$mode objfpc in the system unit can't load objpas that overrides the integer, even if the mode is set.

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 22 lines
On 24-11-2022 14:25, Ondrej Pokorny via fpc-devel wrote: > Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: >> On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >>> >>> I just need to double-check something.  Under CPU16, SizeInt and >>> SizeUInt are declared as follows: >>> >>>   SizeInt = Integer; >>>   SizeUInt = Word; >>> >>> Is Integer 16-bit in this case? >> >> Yes. > > Are you sure? systemh.inc is compiled with {$mode objfpc} (see line > 22), so Integer within the system unit is 32-bit. 1. Then why does the posted code print 2? 2. using {$mode objfpc in the system unit can't load objpas that overrides the integer, even if the mode is set.

Indeed, it seems to me that this directive should be removed from the system unit.

OTOH, it's probably needed to enable classes for the TObject definition ?

Maybe the compiler contains some code to detect this special case.

Michael.

Reply by email

Tomas Hajny
to Ondrej Pokorny: Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer…
Ondrej Pokorny wrote 17 lines
Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: > On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >> >> I just need to double-check something.  Under CPU16, SizeInt and >> SizeUInt are declared as follows: >> >>   SizeInt = Integer; >>   SizeUInt = Word; >> >> Is Integer 16-bit in this case? > > Yes. Are you sure? systemh.inc is compiled with {$mode objfpc} (see line 22), so Integer within the system unit is 32-bit. So to me it looks like a bug.

No, it isn't a bug - systemh.inc is indeed compiled in $MODE OBJFPC nowadays, but it defines Integer = SmallInt on line 110. Depending on compilation mode used for your sources (containing references to Integer), the definition in unit objpas (included automatically for modes objfpc and delphi) may override the definition in systemh.inc.

Tomas

Reply by email

Ondrej Pokorny
to Tomas Hajny
Tomas Hajny wrote 24 lines
On 2022-11-24 14:25, Ondrej Pokorny via fpc-devel wrote: > Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: >> On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >>> >>> I just need to double-check something.  Under CPU16, SizeInt and >>> SizeUInt are declared as follows: >>> >>>   SizeInt = Integer; >>>   SizeUInt = Word; >>> >>> Is Integer 16-bit in this case? >> >> Yes. > > Are you sure? systemh.inc is compiled with {$mode objfpc} (see line > 22), so Integer within the system unit is 32-bit. > > So to me it looks like a bug. No, it isn't a bug - systemh.inc is indeed compiled in $MODE OBJFPC nowadays, but it defines Integer = SmallInt on line 110. Depending on compilation mode used for your sources (containing references to Integer), the definition in unit objpas (included automatically for modes objfpc and delphi) may override the definition in systemh.inc.

All clear now. Thanks!

Ondrej

Reply by email

J. Gareth Moreton
to Michael Van Canneyt: Indeed, it seems to me that this directive should be removed from the system unit. OTOH,…

Would it be better to define "SizeInt = SmallInt;" here just so it's crystal clear what size it is?

Kit

Michael Van Canneyt wrote 40 lines
On Thu, 24 Nov 2022, Marco van de Voort via fpc-devel wrote: > > On 24-11-2022 14:25, Ondrej Pokorny via fpc-devel wrote: >> Am 24.11.2022 um 14:15 schrieb Marco van de Voort via fpc-devel: >>> On 24-11-2022 14:13, J. Gareth Moreton via fpc-devel wrote: >>>> >>>> I just need to double-check something.  Under CPU16, SizeInt and >>>> SizeUInt are declared as follows: >>>> >>>>   SizeInt = Integer; >>>>   SizeUInt = Word; >>>> >>>> Is Integer 16-bit in this case? >>> >>> Yes. >> >> Are you sure? systemh.inc is compiled with {$mode objfpc} (see line >> 22), so Integer within the system unit is 32-bit. > > 1. Then why does the posted code print 2? > > 2. using {$mode objfpc in the system unit can't load objpas that > overrides the integer, even if the mode is set. Indeed, it seems to me that this directive should be removed from the system unit. OTOH, it's probably needed to enable classes for the TObject definition ? Maybe the compiler contains some code to detect this special case. Michael. _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

J. Gareth Moreton
to J. Gareth Moreton

Beg your pardon, it's line 451.  I was looking at the version of the file in FPC 3.2.0, not the trunk.

Kit

J. Gareth Moreton wrote 21 lines
rtl/inc/systemh.inc, line 360 On 24/11/2022 13:52, Michael Van Canneyt via fpc-devel wrote: > > > On Thu, 24 Nov 2022, J. Gareth Moreton via fpc-devel wrote: > >> Would it be better to define "SizeInt = SmallInt;" here just so it's >> crystal clear what size it is? > > Where is 'here' ? > > Michael. > _______________________________________________ > fpc-devel maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to J. Gareth Moreton: rtl/inc/systemh.inc, line 360
J. Gareth Moreton wrote
rtl/inc/systemh.inc, line 360

Latest Git says:

{$ifdef CPURISCV64}
   {$define DEFAULT_DOUBLE}
   {$define FPC_INCLUDE_SOFTWARE_MOD_DIV}
   {$define FPC_INCLUDE_SOFTWARE_MUL}
   {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
   {$ifndef FPUNONE}
     {$define SUPPORT_SINGLE}
     {$define SUPPORT_DOUBLE}
     {$define FPC_INCLUDE_SOFTWARE_INT64_TO_DOUBLE}
// <----- Line 360
     ValReal = Double;
   {$endif}
{$endif CPURISCV64}

So I think the line you mean is 451 in latest git.

But yes, it is probably better to say

SizeInt = SmallInt;

Michael.

Show quoted text 20 lines
On 24/11/2022 13:52, Michael Van Canneyt via fpc-devel wrote: > > > On Thu, 24 Nov 2022, J. Gareth Moreton via fpc-devel wrote: > >> Would it be better to define "SizeInt = SmallInt;" here just so it's >> crystal clear what size it is? > > Where is 'here' ? > > Michael. > _______________________________________________ > fpc-devel maillist  -  > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel > _______________________________________________ fpc-devel maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 7 lines
On 24-11-2022 14:59, Michael Van Canneyt via fpc-devel wrote: > > SizeInt = SmallInt; > (IMHO get rid of small and short in general, and simply put int8/16 instead. But that might require compiler work?)

Agreed.

I would also prefer the use of int8/uint8/int16/uint16 etc. as the basic compiler types, but those will indeed need some compiler work, which is why I didn't propose it.

If they appear, at that point we can define Small/Short/LongInt simply as aliases. It would be much more clear.

Michael.

Reply by email