Sign in Join

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

Mailing lists / fpc-devel / 2023-12

WordBool or SmallInt ?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Martin Frb

fpc 3.2.3
The below prog prints 3 times: 11, -1   (signed values)

https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-250003.1.1

Free Pascal also supports the ByteBool, WordBool, LongBool and QWordBool types. These are of type Byte, Word, Longint or Int64,

Besides the fact that a "QWordBool" should be "Int64", they all seem to be treated as signed.

Yet at least the first two of them are documented as unsigned.

program Project1;
var
b1,b2 : wordbool;
b3,b4 : longbool;
b5,b6 : qwordbool;
begin
b1 := wordBool(11);
b2 := wordBool(-1);
writeln(ord(b1));
writeln(ord(b2));
writeln;
b3 := LongBool(11);
b4 := LongBool(-1);
writeln(ord(b3));
writeln(ord(b4));
writeln;
b5 := qwordBool(11);
b6 := qwordBool(-1);
writeln(ord(b5));
writeln(ord(b6));
readln;
end.

Reply by email

Sven Barth
to Martin Frb

Martin Frb via fpc-devel schrieb am Fr.,
29. Dez. 2023, 20:38:

Show quoted text 12 lines
fpc 3.2.3 The below prog prints 3 times: 11, -1 (signed values) https://www.freepascal.org/docs-html/current/ref/refsu4.html#x26-250003.1.1 Free Pascal also supports the ByteBool, WordBool, LongBool and QWordBool types. These are of type Byte, Word, Longint or Int64, Besides the fact that a "QWordBool" should be "Int64", they all seem to be treated as signed.

The prefix refers to the width, not whether they are signed or not.

Yet at least the first two of them are documented as unsigned.

Internally they are handled as signed, but in the end it doesn't matter, because the only thing that counts for them is whether they're "0" aka "False" or "not 0" aka "True" (though that doesn't mean that all bits need to set, just that any bit needs to be 1).

Regards,
Sven

Reply by email