Forum > General

How to force the not operator to return a byte

(1/14) > >>

Roland57:
Hello!

I have the following code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  a = 128;  b =  64;  c = byte(not(a or b));  beginend.
With FPC 3.2.0, I get this warning; "Warning: range check error while evaluating constants (-193 must be between 0 and 255)"

(With FPC 3.0.4, I didn't get any warning. I don't know why.)

How could I get rid of the warning? I tried several things but didn't find the solution.

Regards.

Roland

winni:
Hi!

If you want to get a correct result and no warning do this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    const      a = byte(128);      b =  byte(64);      c = byte(not(a or b));         begin    end.
Cast both const to a byte to the range of 0..255. Const b is now only in the range 0..64 and so only 7 bits while  128 is 8 bits..

Winni

MarkMLl:
Try


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    const      a: byte= 128;      b: byte=  64;      c { : byte } = not(a or b);         begin    end. 
If that doesn't work try byte(a) etc., i.e. to make it absolutely explicit that you're not expecting it to be extended.

MarkMLl

howardpc:
try
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  a = ShortInt(128);  b = 64;  c = Byte(not(a or b));

Roland57:
Thank you all for your answers.

@howardpc

Your proposition seems to solve the problem, but I don't understand it.  :)

Navigation

[0] Message Index

[#] Next page

Go to full version