Recent

Author Topic: [CLOSED] SizeOf(integer) in Delphi mode  (Read 2546 times)

julkas

  • Guest
[CLOSED] SizeOf(integer) in Delphi mode
« on: December 16, 2019, 11:14:56 am »
From https://www.freepascal.org/docs-html/prog/progse74.html -
Quote
the type Integer is redefined as Longint
and https://wiki.lazarus.freepascal.org/Integer -
Quote
Currently, the integer type is only dependent on $mode, not on the CPU type. An integer is 16-bit in TP or FPC modes, or 32-bit in ObjFPC or Delphi modes.

But Sizeof(Integer) = 2 {$mode delphi} for atmega328p . Please, explain.
Code: Pascal  [Select][+][-]
  1. ...
  2. {$mode delphi}
  3.  
  4. var
  5.   dv: Integer;
  6.  
  7. {$if Sizeof(dv) = 8}
  8. {$info SizeOf(dv) = 8}
  9. {$elseif Sizeof(dv) = 4}
  10. {$info SizeOf(dv) = 4}
  11. {$elseif Sizeof(dv) = 2}
  12. {$info SizeOf(dv) = 2}
  13. {$elseif Sizeof(dv) = 1}
  14. {$info SizeOf(dv) = 1}
  15. {$endif}
  16. ...

Code: Text  [Select][+][-]
  1. $  ppcrossavr.exe -Tembedded -Cpavr5 -Wpatmega328p -vi Blinky.lpr
  2. Target OS: Embedded
  3. Compiling Blinky.lpr
  4. User defined: SizeOf(dv) = 2
  5. Assembling blinky
  6. Linking Blinky
  7. 41 lines compiled, 0.1 sec, 396 bytes code, 2 bytes data
  8.  
« Last Edit: December 16, 2019, 02:42:24 pm by julkas »

Thaddy

  • Hero Member
  • *****
  • Posts: 18729
  • To Europe: simply sell USA bonds: dollar collapses
Re: SizeOf(integer) in Delphi mode
« Reply #1 on: December 16, 2019, 11:18:23 am »
The current (trunk) documentation is better.
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...

ccrause

  • Hero Member
  • *****
  • Posts: 1093
Re: SizeOf(integer) in Delphi mode
« Reply #2 on: December 16, 2019, 02:11:57 pm »
The current (trunk) documentation is better.
As Thaddy mentioned the trunk documentation for Mode Delphi does mention that integer is CPU independent - "Inversely, it means that system.integer is always 16-bit.". Note that the online documentation is specific to FPC 3.0.4.  Anyone 

So taking this testing a bit further; below the size of integer for all modes that can compile a simple AVR test (tested on FPC 3.3.1 from 2019/11/08):
ModeSizeof(integer)Sizeof(NativeInt)
FPC
2
2
Delphi
2
2
DelphiUniUnicode
2
2
TP
2
2
ObjFPC
2
2
ISO
4
2

This implies that the current documentation for Ordinal Types - Integer. Item 1 below table 3.2, is incorrect: "Every platform has a ”native” integer size, depending on whether the platform is 8-bit, 16-bit, 32-bit or 64-bit. e.g. On AVR this is 8-bit".  This hasn't been updated in trunk documentation.

julkas

  • Guest
Re: SizeOf(integer) in Delphi mode
« Reply #3 on: December 16, 2019, 02:39:17 pm »
The current (trunk) documentation is better.
As Thaddy mentioned the trunk documentation for Mode Delphi does mention that integer is CPU independent - "Inversely, it means that system.integer is always 16-bit.". Note that the online documentation is specific to FPC 3.0.4.  Anyone 

So taking this testing a bit further; below the size of integer for all modes that can compile a simple AVR test (tested on FPC 3.3.1 from 2019/11/08):
ModeSizeof(integer)Sizeof(NativeInt)
FPC
2
2
Delphi
2
2
DelphiUniUnicode
2
2
TP
2
2
ObjFPC
2
2
ISO
4
2

This implies that the current documentation for Ordinal Types - Integer. Item 1 below table 3.2, is incorrect: "Every platform has a ”native” integer size, depending on whether the platform is 8-bit, 16-bit, 32-bit or 64-bit. e.g. On AVR this is 8-bit".  This hasn't been updated in trunk documentation.
OK. Thanks and SizeOf(FixedInt) in Delphi mode for atmega328p is 4 bytes.
Code: Text  [Select][+][-]
  1. ...
  2. {$mode delphi}
  3. var
  4.   dv: FixedInt;
  5. ...
  6.  
Code: Text  [Select][+][-]
  1.  ppcrossavr.exe -Tembedded -Cpavr5 -Wpatmega328p -vi -a Blinky.lpr
  2. Target OS: Embedded
  3. Compiling Blinky.lpr
  4. User defined: SizeOf(dv) = 4
  5. Assembling blinky
  6. Linking Blinky
  7. 41 lines compiled, 0.2 sec, 648 bytes code, 4 bytes data

 

TinyPortal © 2005-2018