Sign in Join

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

Mailing lists / fpc-pascal / 2020-03

Range check error warning.

28 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

fredvs

Hello.

With fpc 3.3.1 there is this warning:

"Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255)"

Here the code pointed by the warning:

const
 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 foldlevelmask...

Fre;D

-----
Many thanks ;-)

Reply by email

Unknown author
to fredvs
fredvs wrote 10 lines
const 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 foldlevelmask...

so let's work through it manually... with a little rambling because too much c0ffee...

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
select "NOT"
click calculate

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?

const
   foldhiddenbit : byte = 7;
   foldhiddenmask : byte = 1 shl foldhiddenbit;
   currentfoldhiddenbit : byte = 6;
   currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit;
   foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask);
*or*
   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!*

Reply by email

Alexander Grotewohl
to Unknown author

Yes, those constants are defaulting to integer, which can represent both negative and positive values. When you do your shl you're inadvertently causing them to go into the range that pascal thinks is negative.

The typed constant should fix it.

Alexander Grotewohl https://dcclost.com ________________________________
Earlier message 83 lines
From: fpc-pascal on behalf of Sent: Tuesday, March 24, 2020 11:49:33 AM To: Subject: Re: [fpc-pascal] Range check error warning. On 3/23/20 8:08 PM, fredvs via fpc-pascal wrote: > const > 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 > foldlevelmask... so let's work through it manually... with a little rambling because too much c0ffee... 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 select "NOT" click calculate 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? const foldhiddenbit : byte = 7; foldhiddenmask : byte = 1 shl foldhiddenbit; currentfoldhiddenbit : byte = 6; currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit; foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask); *or* 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!*

Reply by email

fredvs
to Unknown author: so let's work through it manually... with a little rambling because too much c0ffee...…

Hello WKitty.

   foldhiddenmask : byte = 1 shl foldhiddenbit;
   currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit;
   foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask);
  =
  msedatalist.pas(897,47) Error: (3203) Illegal expression
  msedatalist.pas(899,61) Error: (3203) Illegal expression
  msedatalist.pas(900,72) Error: (3203) Illegal expression

Thanks for the links for calculation, indeed the result is -193.

I did play with abs(), for example:

foldlevelmask = abs(byte(not (foldhiddenmask or currentfoldhiddenmask)));

But strangely still that warning:
Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255)

Fre;D

Fre;D

-----
Many thanks ;-)

Reply by email

Alexander Grotewohl
to fredvs

just to be clear.. you did do foldhiddenbit: byte = 7, etc?

Alexander Grotewohl https://dcclost.com ________________________________
Earlier message 42 lines
From: fpc-pascal on behalf of fredvs via fpc-pascal Sent: Tuesday, March 24, 2020 12:22:10 PM To: Cc: fredvs Subject: Re: [fpc-pascal] Range check error warning. Hello WKitty. foldhiddenmask : byte = 1 shl foldhiddenbit; currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit; foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask); = msedatalist.pas(897,47) Error: (3203) Illegal expression msedatalist.pas(899,61) Error: (3203) Illegal expression msedatalist.pas(900,72) Error: (3203) Illegal expression Thanks for the links for calculation, indeed the result is -193. I did play with abs(), for example: foldlevelmask = abs(byte(not (foldhiddenmask or currentfoldhiddenmask))); But strangely still that warning: Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255) Fre;D Fre;D ----- Many thanks ;-) -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/

Reply by email

fredvs
to Alexander Grotewohl

Hello Alexander.

I did:

const
   foldhiddenbit : byte = 7; // line 896
   foldhiddenmask : byte = 1 shl foldhiddenbit; // line 897
   currentfoldhiddenbit : byte = 6; // line 898
   currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit; // line 899
   foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask); //
line 900

That gives that error messages:

msedatalist.pas(897,47) Error: (3203) Illegal expression
msedatalist.pas(899,61) Error: (3203) Illegal expression
msedatalist.pas(900,72) Error: (3203) Illegal expression
msedatalist.pas(1126,1) Fatal: (10026) There were 3 errors compiling module,
stopping

Fre;D

-----
Many thanks ;-)

Reply by email

fredvs
to fredvs

And doing this:

 foldhiddenbit = byte(7);
 foldhiddenmask = byte(1 shl foldhiddenbit);
 currentfoldhiddenbit = byte(6);
 currentfoldhiddenmask = byte(1 shl currentfoldhiddenbit);
 foldlevelmask = abs(byte(not (foldhiddenmask or currentfoldhiddenmask)));
// line 891

Gives also a warning:
msedatalist.pas(891,22) Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255)

OK, I stop.

Fre;D

-----
Many thanks ;-)

Reply by email

Bart
to fredvs: And doing this: foldhiddenbit = byte(7); foldhiddenmask = byte(1 shl foldhiddenbit);…
PM fredvs wrote
OK, I stop.

This works?

{$mode objfpc}
{$apptype console}
const
  foldhiddenbit = byte(7);
  foldhiddenmask = byte(1 shl foldhiddenbit);
  currentfoldhiddenbit = byte(6);
  currentfoldhiddenmask = byte(1 shl currentfoldhiddenbit);
  intermediate = word(byte(foldhiddenmask) or byte(currentfoldhiddenmask));
  intermediate2 = Word(not intermediate);
  foldlevelmask = byte(lo(intermediate2)); //byte(not
(byte(foldhiddenmask) or byte(currentfoldhiddenmask)));
begin
  writeln('intermediate=',intermediate);
  writeln('foldlevelmask=',foldlevelmask);
end.

Prints:
intermediate=192
foldlevelmask=63

Bart

Reply by email

Unknown author
to fredvs: Hello Alexander. I did: const foldhiddenbit : byte = 7; // line 896 foldhiddenmask : byte…
fredvs wrote 19 lines
Hello Alexander. I did: const foldhiddenbit : byte = 7; // line 896 foldhiddenmask : byte = 1 shl foldhiddenbit; // line 897 currentfoldhiddenbit : byte = 6; // line 898 currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit; // line 899 foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask); // line 900 That gives that error messages: msedatalist.pas(897,47) Error: (3203) Illegal expression msedatalist.pas(899,61) Error: (3203) Illegal expression msedatalist.pas(900,72) Error: (3203) Illegal expression msedatalist.pas(1126,1) Fatal: (10026) There were 3 errors compiling module, stopping

you should figure out why typed constants are not being allowed/used in your setup...

https://wiki.freepascal.org/Constants#Scalar_constants https://www.freepascal.org/docs-html/ref/refse10.html

also, what mode are you compiling with? that may be tripping this up if the current mode doesn't allow typed constants...

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

Alexander Grotewohl
to fredvs

perhaps calculate those results by hand and assign them.. then fix it later? hehe

Alexander Grotewohl https://dcclost.com ________________________________
Earlier message 16 lines
From: fpc-pascal on behalf of fredvs via fpc-pascal Sent: Tuesday, March 24, 2020 1:53:19 PM To: Cc: fredvs Subject: Re: [fpc-pascal] Range check error warning. > what mode are you compiling with? {$mode objfpc}{$h+} ----- Many thanks ;-) -- Sent from: http://free-pascal-general.1045716.n5.nabble.com/

Reply by email

Gerhard Scholz
to fredvs: Hello. With fpc 3.3.1 there is this warning: "Warning: (4110) Range check error while…

what about

 foldlevelmask = (not (foldhiddenmask or currentfoldhiddenmask)) and $ff ;
instead of the "  f...  := byte(...) " line

?

Earlier message 45 lines
----- Original Message ----- From: "fredvs via fpc-pascal" To: Cc: "fredvs" Sent: Tuesday, March 24, 2020 1:08 AM Subject: [fpc-pascal] Range check error warning. > Hello. > > With fpc 3.3.1 there is this warning: > > "Warning: (4110) Range check error while evaluating constants (-193 must > be > between 0 and 255)" > > Here the code pointed by the warning: > > const > 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 > foldlevelmask... > > Fre;D > > > > > > > > ----- > Many thanks ;-) > -- > Sent from: http://free-pascal-general.1045716.n5.nabble.com/ > _______________________________________________ > fpc-pascal maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >

Reply by email

Gerhard Scholz
to fredvs
z := x AND y is a bitwise AND

(not (foldhiddenmask or currentfoldhiddenmask))

results in

dec: -193 hex: ffff ff3f bin: 1111 1111 1111 1111 1111 1111 0011 1111

this AND hex: $ff (bin: 11111 1111) gives

bin: 1111 1111 1111 1111 1111 1111 0011 1111
AND
bin: 0000 0000 0000 0000 0000 0000 1111 1111
-------------------------------------------------------------------- bin: 0000 0000 0000 0000 0000 0000 0011 1111

the result now definitely fits in a byte

The operators NOT, AND, OR, XOR (applied to integers) should be mentioned somewhere in the documentation, maybe the explanation there is clearer

Earlier message 34 lines
----- Original Message ----- From: "fredvs via fpc-pascal" To: Cc: "fredvs" Sent: Tuesday, March 24, 2020 8:59 PM Subject: Re: [fpc-pascal] Range check error warning. >> what about > >> foldlevelmask = (not (foldhiddenmask or currentfoldhiddenmask)) and $ff ; > > Ha, this one fpc 3.3.1 like it! > > No more warning nor error. > > May I ask you what "and $ff" does, is it the same as "abs()" or keep it > the > negative value? > > Many thanks. > > Fre;D > > > > ----- > Many thanks ;-) > -- > Sent from: http://free-pascal-general.1045716.n5.nabble.com/ > _______________________________________________ > fpc-pascal maillist - > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal >

Reply by email

Sven Barth
to Unknown author: you should figure out why typed constants are not being allowed/used in your setup...…

schrieb am Di., 24. März 2020, 18:37:

Show quoted text 29 lines
On 3/24/20 12:40 PM, fredvs via fpc-pascal wrote: > Hello Alexander. > > I did: > > const > foldhiddenbit : byte = 7; // line 896 > foldhiddenmask : byte = 1 shl foldhiddenbit; // line 897 > currentfoldhiddenbit : byte = 6; // line 898 > currentfoldhiddenmask : byte = 1 shl currentfoldhiddenbit; // line 899 > foldlevelmask : byte = not (foldhiddenmask or currentfoldhiddenmask); // > line 900 > > That gives that error messages: > > msedatalist.pas(897,47) Error: (3203) Illegal expression > msedatalist.pas(899,61) Error: (3203) Illegal expression > msedatalist.pas(900,72) Error: (3203) Illegal expression > msedatalist.pas(1126,1) Fatal: (10026) There were 3 errors compiling module, > stopping you should figure out why typed constants are not being allowed/used in your setup...

Typed constants can not be used to initialize constants.

Regards,
Sven

Reply by email

Sven Barth
to fredvs: Hello. With fpc 3.3.1 there is this warning: "Warning: (4110) Range check error while…
fredvs wrote 19 lines
Hello. With fpc 3.3.1 there is this warning: "Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255)" Here the code pointed by the warning: const 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 foldlevelmask...

Splitting the last constant a bit more allows to find the culprit:

=== code begin ===
const
   const1 = foldhiddenmask or currentfoldhiddenmask;
   const2 = not const1;
   const3 = byte(not const2);

=== code begin ===

The compiler will now complain on const3 (and a check with SizeOf(...) reveils that const2 is not of Byte size). I'll have to investigate however why the "not" behaves as it does.

Regards,
Sven

Reply by email

Unknown author
to Sven Barth: schrieb am Di., 24. März 2020, 18:37: Typed constants can not be used to initialize…
Sven Barth wrote 6 lines
schrieb am Di., 24. März 2020, 18:37: > you should figure out why typed constants are not being allowed/used > in your setup... Typed constants can not be used to initialize constants.

hummm... ok, so how to you get a constant to be a byte and storing 7 for the decimal value?

or are you saying that you cannot use a typed constant in the init of another (typed) constant?

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

Sven Barth
to Unknown author

schrieb am Mi., 25. März 2020, 18:47:

Show quoted text 13 lines
On 3/24/20 6:58 PM, Sven Barth via fpc-pascal wrote: > schrieb am Di., 24. März 2020, 18:37: > >> you should figure out why typed constants are not being allowed/used >> in your setup... > > Typed constants can not be used to initialize constants. hummm... ok, so how to you get a constant to be a byte and storing 7 for the decimal value?

The compiler normally uses the smallest possible type that can represent the value. You can force it however by using e.g.

const
  MyConst = Word(42);
or are you saying that you cannot use a typed constant in the init of another (typed) constant?

Correct.

Regards,
Sven

Reply by email

Howard Page-Clark
to Unknown author: hummm... ok, so how to you get a constant to be a byte and storing 7 for the decimal…
Show quoted text 14 lines
On 3/24/20 6:58 PM, Sven Barth via fpc-pascal wrote: > schrieb am Di., 24. März 2020, 18:37: > >> you should figure out why typed constants are not being allowed/used >> in your setup... > > Typed constants can not be used to initialize constants. hummm... ok, so how to you get a constant to be a byte and storing 7 for the decimal value? or are you saying that you cannot use a typed constant in the init of another (typed) constant
Try
const
   seven = Byte(7);

Reply by email

Unknown author
to Sven Barth: schrieb am Mi., 25. März 2020, 18:47: The compiler normally uses the smallest possible…
Sven Barth wrote 11 lines
schrieb am Mi., 25. März 2020, 18:47: > hummm... ok, so how to you get a constant to be a byte and storing 7 for the > decimal value? The compiler normally uses the smallest possible type that can represent the value. You can force it however by using e.g. const   MyConst = Word(42);

ok... so in the situation this thread is covering:

const
   foldhiddenbit = byte(7);
   foldhiddenmask = byte(1 shl foldhiddenbit);
   currentfoldhiddenbit = byte(6);
   currentfoldhiddenmask = byte(1 shl currentfoldhiddenbit);
   foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask));

is the way to do it?

> or are you saying that you cannot use a typed constant in the init of another > (typed) constant? Correct.

strange...

[wargames] seems like the winning move is to not play the game. [/wargames] LUL

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

Unknown author
to Bart
Bart wrote 6 lines
On Wed, Mar 25, 2020 at 7:48 PM wrote: > [wargames] seems like the winning move is to not play the game. [/wargames] LUL LUL ?? What does that stand for?

it is the LOL emoticon with a beard... i've gotten to where i use it all the time instead of plain old lol... especially since i am bearded these days ;)

Better not say that to someone who speaks Dutch (like me) ;-))

what? you don't like laughing bearded guys?

https://knowyourmeme.com/memes/lul

NOTE: No off-list assistance is given without prior approval. *Please keep mailing list traffic on the list where it belongs!*

Reply by email

Sven Barth
to Unknown author: ok... so in the situation this thread is covering: const foldhiddenbit = byte(7);…

schrieb am Mi., 25. März 2020, 19:48:

Show quoted text 27 lines
On 3/25/20 2:17 PM, Sven Barth via fpc-pascal wrote: > schrieb am Mi., 25. März 2020, 18:47: > >> hummm... ok, so how to you get a constant to be a byte and storing 7 for the >> decimal value? > > > The compiler normally uses the smallest possible type that can represent the > value. You can force it however by using e.g. > > const > MyConst = Word(42); ok... so in the situation this thread is covering: const foldhiddenbit = byte(7); foldhiddenmask = byte(1 shl foldhiddenbit); currentfoldhiddenbit = byte(6); currentfoldhiddenmask = byte(1 shl currentfoldhiddenbit); foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask)); is the way to do it?

In theory, yes, but for some reason the "not" upsets this. I have yet to investigate why though and whether this is by design.

Regards,
Sven

Reply by email