Recent

Author Topic: is there a special requirement to use boolean8 ?  (Read 7598 times)

440bx

  • Hero Member
  • *****
  • Posts: 3945
is there a special requirement to use boolean8 ?
« on: July 29, 2018, 09:26:57 pm »
Hello,

I was trying the Boolean types supported by FPC.
 
The page https://www.freepascal.org/docs-html/ref/refsu4.html says there is a type boolean8 but, when I tried it, the compiler was not happy.  It complained about Boolean8 being an "identifier not found". 

Did I miss something or is what is stated on that page not quite right ?

Thanks.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: is there a special requirement to use boolean8 ?
« Reply #1 on: July 29, 2018, 09:43:46 pm »
 
The page https://www.freepascal.org/docs-html/ref/refsu4.html says there is a type boolean8 but, when I tried it, the compiler was not happy.  It complained about Boolean8 being an "identifier not found". 
if I look at symdef.pas and psystem.pas it is indeed not registered to the compiler, although the underlying pasbool8type IS defined. The rest are all registered to the compiler.
It is also not defined for the debugger.

Pls file a bug report.
« Last Edit: July 29, 2018, 09:50:25 pm by Thaddy »
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: is there a special requirement to use boolean8 ?
« Reply #2 on: July 29, 2018, 10:17:25 pm »
Pls file a bug report.

Done!  Thank you for looking into it.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: is there a special requirement to use boolean8 ?
« Reply #3 on: August 01, 2018, 05:28:55 pm »
The type you're looking for is Boolean. If at all the Boolean8 would be added as an alias to that...

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: is there a special requirement to use boolean8 ?
« Reply #4 on: August 01, 2018, 06:13:38 pm »
The type you're looking for is Boolean. If at all the Boolean8 would be added as an alias to that...
well, Sven: it is actually in the compiler sources... Just not registered.
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: is there a special requirement to use boolean8 ?
« Reply #5 on: August 03, 2018, 09:51:25 pm »
Did you even search for pasbool8type? Apparantly not, otherwise you'd have found the following in psystem.pas starting at line 454:
Code: Pascal  [Select][+][-]
  1.         addtype('Boolean',pasbool8type);
  2.         addtype('Boolean16',pasbool16type);
  3.         addtype('Boolean32',pasbool32type);
  4.         addtype('Boolean64',pasbool64type);
  5.         addtype('ByteBool',bool8type);
  6.         addtype('WordBool',bool16type);
  7.         addtype('LongBool',bool32type);
  8.         addtype('QWordBool',bool64type);

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: is there a special requirement to use boolean8 ?
« Reply #6 on: August 03, 2018, 10:45:03 pm »
The type you're looking for is Boolean. If at all the Boolean8 would be added as an alias to that...
According to _some_ documentation, there is a Boolean8 type which is somewhat of an alias for plain Boolean.

Refer to this page:

https://www.freepascal.org/docs-html/ref/refsu4.html

According to that page, there is a Boolean8 type (the compiler disagrees) which functions as;
Quote
The only difference with the Boolean8/16/32/64 types is in what values are considered true or false: The value False is equivalent to 0 (zero) and any nonzero value is considered True when converting to a boolean value. A boolean value of True is converted to Not(0) in case it is assigned to a variable of type ByteBool, WordBool, LongBool or QWordBool.

The reference manual on the other hand, makes no mention at all of Boolean8, Boolean16, Boolean32 and Boolean64 (of which, the last 3, the compiler does recognize.)

Bottom line is, there exists Boolean16, Boolean32 and, Boolean64 as well as their very closely related types, WordBool, LongBool and QWordBool.  The existence of Boolean8 would have made the whole thing fully orthogonal and seems to have been forgotten.  Not that it matters much, there are more than enough Boolean types available to accomplish whatever needs to be done.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

kupferstecher

  • Hero Member
  • *****
  • Posts: 583
Re: is there a special requirement to use boolean8 ?
« Reply #7 on: August 03, 2018, 10:57:35 pm »
Code: Pascal  [Select][+][-]
  1.         addtype('Boolean',pasbool8type);
Does that mean type boolean variables always occupy one byte?

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: is there a special requirement to use boolean8 ?
« Reply #8 on: August 03, 2018, 11:03:54 pm »
Code: Pascal  [Select][+][-]
  1.         addtype('Boolean',pasbool8type);
Does that mean type boolean variables always occupy one byte?
Yes, a variable declared as "Boolean" should occupy one byte.  On the other hand, as far as the "always", if the variable is part of a bitpacked record, it may occupy only 1 bit (I haven't tried that yet but, it seems to be the case.)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: is there a special requirement to use boolean8 ?
« Reply #9 on: August 04, 2018, 04:29:06 pm »
The type you're looking for is Boolean. If at all the Boolean8 would be added as an alias to that...
According to _some_ documentation, there is a Boolean8 type which is somewhat of an alias for plain Boolean.

Refer to this page:

https://www.freepascal.org/docs-html/ref/refsu4.html

That was a bug in the documentation which Michael already fixed in the source of the documentation. Also if in doubt the compiler's implementation takes precedence.

Bottom line is, there exists Boolean16, Boolean32 and, Boolean64 as well as their very closely related types, WordBool, LongBool and QWordBool.  The existence of Boolean8 would have made the whole thing fully orthogonal and seems to have been forgotten.  Not that it matters much, there are more than enough Boolean types available to accomplish whatever needs to be done.

Bottom line is that the 8-bit Boolean type has always been there.

Code: Pascal  [Select][+][-]
  1.         addtype('Boolean',pasbool8type);
Does that mean type boolean variables always occupy one byte?
Yes, a variable declared as "Boolean" should occupy one byte.  On the other hand, as far as the "always", if the variable is part of a bitpacked record, it may occupy only 1 bit (I haven't tried that yet but, it seems to be the case.)

Correct. The size of a Boolean type is 1 Byte. Also correct is that in a bitpacked record or array it occupies 1 bit which is also true for the other Boolean types.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: is there a special requirement to use boolean8 ?
« Reply #10 on: August 04, 2018, 06:02:09 pm »
That was a bug in the documentation which Michael already fixed in the source of the documentation. Also if in doubt the compiler's implementation takes precedence.
It's rather convenient to simply declare "there is a bug in the documentation", which may occasionally be the case but, the compiler does recognize Boolean16, Boolean32 and Boolean64.  It follows from that, that the compiler should recognize Boolean8.  Orthogonality is a "nice feature" in a compiler.

       
Bottom line is that the 8-bit Boolean type has always been there.
I don't see anyone in this thread claiming that wasn't the case.  What is the case is that there is a documented Boolean8 (recently and conveniently declared to be a "bug" in the documentation), which the compiler doesn't accept in spite of the fact that it accepts Boolean16, Boolean32 and Boolean64. Bottom line: good design would require the compiler to support Boolean8 and not simply claim that the documentation is "wrong"/"buggy". 

Another bottom line: declaring bugs takes less work than fixing them.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: is there a special requirement to use boolean8 ?
« Reply #11 on: August 04, 2018, 08:09:55 pm »
I have to agree with Sven, in this case an alias is easy to add. If you want a distinct type:
Code: Pascal  [Select][+][-]
  1. type
  2.   Boolean8 = type Boolean;  // more correct than Boolean8=Boolean
What I agree somewhat with you is that this can be in the RTL in system.pas. As a distinct type.
Then nobody can complain. [edit] I requested feedback on my report: a typed type is not strictly an alias and it describes better what it is in the context of the other Boolean16 etc types.
That's even if the underlying type Boolean has the same sign, size and resoluton.
« Last Edit: August 05, 2018, 07:52:52 am by Thaddy »
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: is there a special requirement to use boolean8 ?
« Reply #12 on: August 07, 2018, 12:14:45 pm »
If it would be added to the RTL at all it would be added as a non-distinct type alias just like the aliases for e.g. Int8 and friends.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: is there a special requirement to use boolean8 ?
« Reply #13 on: August 07, 2018, 03:12:27 pm »
If it would be added to the RTL at all it would be added as a non-distinct type alias just like the aliases for e.g. Int8 and friends.
That's a strange answer (for lack of any other polite words  8-) ) because all of them should be strongly typed in the first place!
Anyway. It's ok with me but not that there's any theory behind it... ;) :'( O:-).
A certain theory would explain why we have typed types.... :P

(Sven knows I am not  angry)
« Last Edit: August 07, 2018, 03:14:04 pm by Thaddy »
Specialize a type, not a var.

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: is there a special requirement to use boolean8 ?
« Reply #14 on: September 19, 2018, 10:56:45 am »
For some reason you can't put a ByteBool into a bitpacked record though ("internal error 200706094").

 

TinyPortal © 2005-2018