[fpc-pascal] Range check error warning.
wkitty42 at windstream.net
wkitty42 at windstream.net
Tue Mar 24 16:49:33 CET 2020
On 3/23/20 8:08 PM, fredvs via fpc-pascal wrote:
> foldhiddenbit = 7;
> foldhiddenmask = 1 shl foldhiddenbit;
> currentfoldhiddenbit = 6;
> currentfoldhiddenmask = 1 shl currentfoldhiddenbit;
> foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask));
> -------->Here the warning
> I dont understand how the compiler can find -193 as value for
so let's work through it manually... with a little rambling because too much
foldhiddenmask is 10000000 binary (128 decimal; 80 hex)
currentfoldhiddenmask is 01000000 binary (64 decimal; 40 hex)
ORing them gives 11000000 binary (192 decimal; c0 hex)
applying the NOT gives 00111111 binary (63 decimal; 3f hex)
so that seems to come out as expected but i found several online bitwise
calculators that came with the same -193 answer that fpc returned... this seems
to be related to a wrong field initialization of some kind or using the wrong
size for the value...
go here: http://easyonlineconverter.com/converters/bitwise-calculator.html
place 11000000 in field 1
leave field 2 blank
this one, https://toolslick.com/math/bitwise/not-calculator , gives the same
-193 result but you can also see that it is using 16 bits (word) instead of 8
bits (byte) so the top 8 zero bits are also NOTted which makes them ones and
there's the error... 1111111100111111 == -193... so i tried to trick it and used
16bits... damned thing prepended 8 more ones to the beginning... they're not
respecting that this is a byte we're working with...
i almost feel like telling both of them and the others i found that their
calculators are broken pretty badly... so back to your immediate problem...
apparently your byte() is not working as desired?
perhaps byte() is in the wrong place? perhaps it should be
foldlevelmask = not (byte(foldhiddenmask) or byte(currentfoldhiddenmask));
perhaps the top 8 bits need to be cleared by forcing them to zeros somehow if
the default size of a const is larger than a byte?
perhaps it should be specified that all four of foldhiddenbit, foldhiddenmask,
currentfoldhiddenbit, currentfoldhiddenmask are of byte instead of word or other?
foldhiddenbit : byte = 7;
foldhiddenmask : byte = 1 shl foldhiddenbit;
currentfoldhiddenbit : byte = 6;
currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit;
foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask);
foldlevelmask : byte = not (byte(foldhiddenmask) or byte(currentfoldhiddenmask));
NOTE: i do not currently have FPC (or lazarus) installed so i haven't tested
this in fpc... i needed some drive space a few weeks back and it was easiest to
remove fpc and lazarus at the time... especially since i had four or five
versions of each installed with full source code...
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list where it belongs!*
More information about the fpc-pascal