PDA

View Full Version : Impossible "integer expression" errors



Robert Kosek
21-03-2008, 10:54 PM
I've been making my own list class that is generic and uses a variety of optimized methods. Unfortunately, though, I now get "invalid integer expression" errors at 5+ locations and cannot test the unit. Worse, these errors are ... inane.

These are all integer operations that work, yet generated errors. See for yourself.

Line 87 Column 9:
B := -1; // -1 is within the integer range I'm familiar with!
Line 116 Column 14:
if idx <> -1 then
Line 127 Column 14:
if idx <> -1 then
Line 194 Column 12:
Find &#58;= -1; // assignment to "result"
Line 235 Column 11:
if F = -1 then Exit;

Have I done something particularly crash-worthy? The source code (http://files.thewickedflea.com/index.php?p=get&f=7) (11kb) is under MPL.

Compiler options of note:
Dialect = Object Pascal (FPC)
Optimization = Faster Code

JSoftware
22-03-2008, 11:16 AM
That's some funky stuff there. Must be a compiler bug. It compiles if you write 0-1 instead of -1 though

Robert Kosek
22-03-2008, 11:24 AM
You're kidding! 0-1 works? Maybe typecast it to an integer and it'll work then.

http://bugs.freepascal.org/view.php?id=11035

Robert Kosek
22-03-2008, 12:29 PM
Okay, this appears to be a bug in generic types for FPC 2.2.0, but is fixed in 2.2.1. If only 2.2.1 was the front page release that was marked as stable, rather than the 2.2.0 release.

Edit: Still broken; reopening ticket.

Robert Kosek
22-03-2008, 02:00 PM
And it compiles when you put 0-1 for -1, yes, but it won't run because of:
An unhandled exception occurred at $004016C3 &#58;
ERangeError &#58; Range check error
$004016C3
$00401BA8
$00401FB2

No idea how to even work around this.

JSoftware
22-03-2008, 02:10 PM
It compiles and runs fine for me in version 2.2.0

Robert Kosek
22-03-2008, 02:28 PM
Well, with 2.2.1 it produces that range check error, as you see, and chokes and dies. So I'll have to revert. Looks like their hack isn't nearly so stable as they thought it was. :?

The website is horribly slow, so I'm having trouble posting that addendum with the additional 2.2.1 trouble.

arthurprs
22-03-2008, 03:57 PM
does not compile here

http://aycu19.webshots.com/image/47258/2004733447510546734_rs.jpg (http://allyoucanupload.webshots.com/v/2004733447510546734)

Robert Kosek
22-03-2008, 04:38 PM
Mode must be "Object Pascal extension on" under Options > Compiler.

Almindor
27-03-2008, 09:02 AM
Compiles and runs fine with 2.2.1 here, I get all success 1 failure (as expected, since you go to .Count not .Count - 1).

I uses -O2 -S2 -XX -Xs for options.

With range check on I get some errors, but they seemed to be valid (I got none of the -1 problems). For example your code:


if AnsiCompareText&#40;fNames&#91;I&#93;, fNames&#91;I+1&#93;&#41; > 0 then begin


Which is on line 112 of uFastList.pas is broken, because I + 1 is 1 too big for fNames. So the range check worked fine there.

arthurprs
27-03-2008, 05:17 PM
someone can post here both languages sources?

Robert Kosek
27-03-2008, 05:45 PM
Wait a few moments arthurprs, the present version online is vastly outdated.

Almindor:
Yes, I learned of 2.2.1 and how to obtain it. Now I have Lazarus 0.9.25 and my opinion of Lazarus itself has risen several notches. It works flawlessly in 0.9.25 without any errors, and I've added a good number of new features.

As to that error, it looks like Wikipedia has an error in its Cocktail Sort algorithm's pseudocode. The fix is to set end to an initial value of "fItemCount -2" instead of "- 1". It works exactly the same but with no range check errors.


New Stuff:
Deletion! This includes deletion by index, name, and batch deletion by either index or name. The batch deletion also employs an underhanded trick to increase performance: it deletes from the largest index downwards and puts the last element into the deleted index, then sorts the list with the cocktail sort when done. (IE, it's way fast. Read the source for yourself to see how I do it.)

Added the ability to Comb Sort for those huge lists that may be needed. Because comb sort works over gaps, this makes it more efficient on random arrays of sizable length. Cocktail sort is no wimp though.

Resize now sizes down when items are deleted.

Loads of documentation. :shock:

Download - 384kb, MPL 1.1 License (http://files.thewickedflea.com/index.php?p=get&f=7)
Requires: FPC 2.2.1 03/27/2008 or Lazarus 0.9.25 (http://www.hu.freepascal.org/lazarus/) (Read carefully, if it has a different date than the one listed here I will upload a copy to my webserver just in case.)