Recent

Author Topic: which is better byte or integer ??  (Read 8217 times)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: which is better byte or integer ??
« Reply #15 on: August 16, 2017, 10:36:51 am »
Or use 0

Code: Pascal  [Select][+][-]
  1. var i :0..20;

and let the compiler decide. This was the original pascal/Wirthian way to solve this. Some machines can subdivide large registers easily, and some not.

Wooooo

what is it?

It is a subrange type, only in this case an anonymous subrange type. The compiler knows what underlying type it provides for the variable, but since the programmer has not named it, it is not readily accessible.
If you want to use the type say in a parameter list you would have to name it
Code: Pascal  [Select][+][-]
  1. type
  2. TSmall = 0..20;
Then you could use it in code like this
Code: Pascal  [Select][+][-]
  1. function SmallToStr(aSmall: TSmall): string;
  2. begin ...

I don't know if the compiler consistently applies the same type to such constructs across all platforms, but on my Linux 64-bit computer the following program
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. uses typinfo;
  4.  
  5. var
  6.   i: 0..20;
  7.   pti: PTypeInfo;
  8.  
  9. begin
  10.   pti:=TypeInfo({%H-}i);
  11.   WriteLn(GetEnumName(Typeinfo(TTypeKind),Ord(pti^.Kind)));
  12.   ReadLn;
  13. end.

yields tkInteger.

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: which is better byte or integer ??
« Reply #16 on: August 16, 2017, 10:46:03 am »
yields tkInteger.
Yes. Correct. There's no tkWhatEverIdecidedToBeTheRange.... (Really silly <grumpy  >:D>)

Ask Sven to implement it! He goes nuts! :o
« Last Edit: August 16, 2017, 10:50:58 am by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: which is better byte or integer ??
« Reply #17 on: August 16, 2017, 11:05:30 am »
i question from myself what is different between Byte and Integer?

See :
http://wiki.freepascal.org/Variables_and_Data_Types
True (in this case...) but the wiki  is often incorrect and/or incomplete.
FPC has proper manuals and so FPC has also proper documentation here: https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-260003.1.1
Note that is the only reliable source. If you refer to the wiki, plz first check if it is in the official documentation and use that instead.
That would be really helpful. (albeit for the famed RTFM) :D
I'll take that 'rap on the knuckles'  :o   but plead that I have a number of links on my desktop, one of which is to the full manual and another to the link I posted which was one of the first I found last year. It gives me a very quick reminder (at my age I need reminders!) of the range allowed without opening the manual and then searching for the topic. I could, of course, create a new link directly to the appropriate page in the manual but since the wiki link is in place I haven't found a pressing need. I DO RTFM on occasion  O:-)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: which is better byte or integer ??
« Reply #18 on: August 16, 2017, 12:34:48 pm »
but since the wiki link is in place I haven't found a pressing need. I DO RTFM on occasion  O:-)
I would strongly advise to do the opposite: manual first, wiki later...
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: which is better byte or integer ??
« Reply #19 on: August 16, 2017, 12:59:20 pm »
Use Integer for calculations, as it should be faster due to low level optimizations, such as alignment, and Byte for storing, in order to save memory/storage.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: which is better byte or integer ??
« Reply #20 on: August 16, 2017, 01:09:12 pm »
Use Integer for calculations, as it should be faster due to low level optimizations, such as alignment, and Byte for storing, in order to save memory/storage.
Which integer? The default for fpc is still 16bit and highly inefficient....
Code: Pascal  [Select][+][-]
  1. program intsize;
  2. begin
  3. writeln(SizeOf(Integer));
  4. end.
Compile as fpc intsize:
Code: [Select]
pi@raspberrypi:~/fpcdemos $ fpc -B intsize.pas
Free Pascal Compiler version 3.1.1-r36912 [2017/08/15] for arm
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling intsize.pas
Linking intsize
4 lines compiled, 0.6 sec
pi@raspberrypi:~/fpcdemos $ ./intsize
2 <---!!!!!
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: which is better byte or integer ??
« Reply #21 on: August 16, 2017, 01:46:05 pm »
Which integer? The default for fpc is still 16bit and highly inefficient....
Code: Pascal  [Select][+][-]
  1. program intsize;
  2. begin
  3. writeln(SizeOf(Integer));
  4. end.
Compile as fpc intsize:
Code: [Select]
pi@raspberrypi:~/fpcdemos $ fpc -B intsize.pas
Free Pascal Compiler version 3.1.1-r36912 [2017/08/15] for arm
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling intsize.pas
Linking intsize
4 lines compiled, 0.6 sec
pi@raspberrypi:~/fpcdemos $ ./intsize
2 <---!!!!!
Size of integer is platform specific. 16bit - is something from Turbo Pascal and MS-DOS era. Should be at least 32bit on all modern platforms. May be wrong platform configuration? ARM Cortex-A53 should be 64bit, as I know, and SizeOf(Integer) = 4 for both Win32 and Win64.
« Last Edit: August 16, 2017, 01:55:00 pm by Mr.Madguy »
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: which is better byte or integer ??
« Reply #22 on: August 16, 2017, 03:59:51 pm »
Integer is afaik only dependent on Mode. (weird backends like java JVM excluded maybe)

Turbopascal like - 2 bytes, delphi like (object pascal like) - 4 byte.

Thaddy

  • Hero Member
  • *****
  • Posts: 14390
  • Sensorship about opinions does not belong here.
Re: which is better byte or integer ??
« Reply #23 on: August 16, 2017, 04:07:31 pm »
@Mr.Madguy
Integer is afaik only dependent on Mode. (weird backends like java JVM excluded maybe)

Turbopascal like - 2 bytes, delphi like (object pascal like) - 4 byte.
Correct. fpc mode (still the default!) also specifies integer as 2 bytes.
https://www.freepascal.org/docs-html/current/ref/refsu4.html
https://www.freepascal.org/docs-html/user/userse33.html
http://wiki.freepascal.org/Integer

It is incorrect to link integer size to processor or platform. That is simply wrong.
It is only correct to link integer size to mode and this is well documented.
« Last Edit: August 16, 2017, 04:10:45 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018