0

I'm currently porting a small app that used longbool in some instances and would have used a bool64 type if I could find one. It's not a big issue to change the type to in64 and then set/check for 0 to find if true/false but if there was some way to enable bool64 I'd use it.

Anyone know?

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
Marladu
  • 545
  • 5
  • 11
  • 1
    A Boolean holds two values (true and false). `LONGBOOL` exists only for compatibility with data types used in the WinAPI (where it only exists for compatibility with other types). There isn't, never has been, and most likely never will be a Bool64 type. What possible use could you have for one? – Ken White Jan 06 '15 at 19:30

2 Answers2

2

There is no 64 bit wide boolean type. The boolean types are listed in the documentation:

The 4 predefined Boolean types are Boolean, ByteBool, WordBool, and LongBool. Boolean is the preferred type. The others exist to provide compatibility with other languages and operating system libraries.

A Boolean variable occupies one byte of memory, a ByteBool variable also occupies one byte, a WordBool variable occupies 2 bytes (one word), and a LongBool variable occupies 4 bytes (2 words).

So if you need a 64 bit type that acts as a boolean, you will have to use a 64 bit integer. You could probably make the syntax more amenable with an enhanced record with implicit cast operators to and from Boolean.

I can't imagine why you'd ever need a 64 bit boolean. I've never come across a library that uses such a type. I wonder if you are mis-thinking.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I'm porting over a client's medium size 32bit project where they used longbool (typecasts or directly) a bunch, and I would have simply added something like "type longbool=bool64;" if there was one and be done very quickly with this. Since this contract is about porting this app to 64bit (not optimizing or improving otherwise) for the lowest possible cost every minute (and thus dollar) matters. – Marladu Jan 06 '15 at 19:46
  • 1
    You've got the wrong end of the stick. You don't need to change 32 bit types to 64 bit, other than pointers. Integer is 32 bits wide on all platforms. You don't want types that float between 32 and 64 bits because that causes incompatibility between 32 and 64 bit versions. And LongBool is used for interop. It's 32 bits everywhere. If you use a 64 bit type, the interop won't work. I write all this based on my experience maintaining a large app that compiles to 32 and 64 bit versions from the same source. – David Heffernan Jan 06 '15 at 19:51
  • With a typical simple small app you would simply add the Win64 target and make no changes at all. If you had cast pointers to integers you'd cast woth NativeInt rather than Integer. Or re-write. Without casts. But you should not need any conditional code, as a general rule, and you should not need type aliases like you showed in your comment. – David Heffernan Jan 06 '15 at 19:56
  • I agree and understand but however that happened the app has typecasts of longbool over pointers for variables and function results so I gotta deal with it. – Marladu Jan 06 '15 at 19:56
  • I think I'd deal with that by comparing the pointer against nil rather than casting to a boolean type. I'd definitely fix the code so that it is clean if you want a nice port. – David Heffernan Jan 06 '15 at 19:59
  • That's what I intend to do, I just wanted to check for options. Thanks for your answer. – Marladu Jan 06 '15 at 20:03
  • @Marladu Why is it typecasting pointers to boolean? As David said, the best way to handle that is to fix the code, but rather than comparing to pointer to `nil` directly I'd recommend using Assigned(P) - this does the same thing but is the canonical Delphi way. It returns true if a pointer or reference is non-nil. More details: http://stackoverflow.com/questions/4484002/assigned-vs-nil – David Jan 06 '15 at 20:51
0

FreePascal has a 64-bit C boolean type, and calls it "qwordbool"

Marco van de Voort
  • 25,628
  • 5
  • 56
  • 89