Sign in Join

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

Mailing lists / fpc-pascal / 2021-12

Is there a range limitation for the in operator?

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Bo Berglund

I have been debugging a file analyzer program which is supposed to show a record if one clicks in the hex representation of the binary file content.

I have a function which will grab the start and length of a record given the address clicked on.

The file contains several different sections, basically:
- header (30 bytes)
- array of type 1 records (n * 14 bytes)
- array of type 2 records (m * 25 bytes)
The counts m and n are available in the header record as word size values.

So I have this construct to translate theinput address into a start and length
result:
if Addr in [0..sizHd-1] then  //Clicked in the header
begin
  //Calculate start and end address of header
end
else if Addr in [(sizHd)..(sizHd + sizGeos -1)] then
begin
  //Calculate start and end address of clicked record in array
end
else if Addr in [(sizHd + sizGeos)..(sizHd + sizGeos + sizCmds -1)] then
begin
  //Calculate start and end address of clicked record in array
end;

This seemingly worked fine until I clicked inside the area of he type 2 records, when the execution never got to the last calculation...

So I changed the code from using "in" to this instead:

else if (Addr >= strtCmds) and (Addr < (strtCmds + sizCmds)) then
Where I previously have done this:
strtCmds := strtElecs + sizGeos;

Now it works as planned....

So I wonder if there is a value range limitation for the arguments inside an in command like:
if a in [x..y] then

???

Bo Berglund Developer in Sweden
Sven Barth
to Bo Berglund

Bo Berglund via fpc-pascal schrieb am
Mi., 22. Dez. 2021, 16:08:

Show quoted text 5 lines
So I wonder if there is a value range limitation for the arguments inside an in command like: if a in [x..y] then

The right side of the in-operator is a set constructor. And sets may only contain up to 256 values. (Though I don't know right now whether that is always counted from 0 or not)

Regards,
Sven

Bo Berglund
to Sven Barth
Sven Barth wrote 13 lines
Bo Berglund via fpc-pascal schrieb am Mi., 22. Dez. 2021, 16:08: > So I wonder if there is a value range limitation for the arguments inside > an in > command like: > if a in [x..y] then > The right side of the in-operator is a set constructor. And sets may only contain up to 256 values. (Though I don't know right now whether that is always counted from 0 or not)

Ok, thanks. Figured that it was something like that. So I have to stack several if conditions instead.

Bo Berglund Developer in Sweden