Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
Sorry I am a never-give-it-up... So, about those famous 2 last warnings: I propose this to make the compiler happy: - First warning: > msedatalist.pas(891,18) Warning: (4110) Range check error while evaluating > constants (-193 must be between 0 and 255) Point to: foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask)); I propose this instead (see abs()): foldlevelmask = byte(abs(not (foldhiddenmask or currentfoldhiddenmask))); - Last warning: > mseactions.pas(762,34) Warning: (4110) Range check error while evaluating > constants (-63489 must be between 0 and 65535) Point to: result:= (key <> 0) and (key <> word(not modmask)); I propose this instead (see abs()): result:= (key <> 0) and (key <> word(abs(not modmask))); What do you think? Fre;D -- Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/ ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
why not just replace byte with integer , i am not sure ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
why not just replace byte with integer , i am not sure ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
> why not just replace byte with integer I just try it and with this you get 8 new warnings... -- Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/ ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
What is very strange is that I get also a warning with this (see abs() added): const foldhiddenbit = 7; foldhiddenmask = abs(1 shl foldhiddenbit); currentfoldhiddenbit = 6; currentfoldhiddenmask = abs(1 shl currentfoldhiddenbit); foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask)); // here warning msedatalist.pas(891,18) Warning: (4110) Range check error while evaluating constants (-193 must be between 0 and 255) So only this make him happy: foldlevelmask = byte(abs(not (foldhiddenmask or currentfoldhiddenmask))); -- Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/ ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
The same for the last warning: Changing with this: modmask = abs(shift or ctrl or alt or $1000 or pad); ... result:= (key <> 0) and (key <> word((not modmask))); Gives the warning: mseactions.pas(763,34) Warning: (4110) Range check error while evaluating constants (-63489 must be between 0 and 65535) Only this make fpc happy: result:= (key <> 0) and (key <> word(abs(not modmask))); ? Fre;D -- Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/ ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
Hello fredvs, you wrote on Sun, 29 Mar 2020 08:36:10 -0700 (MST): > So, about those famous 2 last warnings: > > I propose this to make the compiler happy: ... > > msedatalist.pas(891,18) Warning: (4110) Range check error while > > evaluating constants (-193 must be between 0 and 255) > >Point to: >foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask)); > >I propose this instead (see abs()): >foldlevelmask = byte(abs(not (foldhiddenmask or > currentfoldhiddenmask))); I'm rather afraid that this will _not_ result in the intended value. I.e. a statement testing an expression of either "foldhiddenmask" or "currentfoldhiddenmask" against the value of "foldlevelmask" will _not_ neccessarily always fail (it should fail because of the "not"). This seems to derive from an uncanny mixture of signed and unsigned values, perhaps due to a range overflow during evaluation of the expression, triggering an unwanted sign extension and thus turning an unsigned value "negative". -193 is $FF3F(32bit), byte ($3F) = 63, NOT $3F = $C0 = 192. So it seems the expression ors together bit 6 & 7 of a byte-size type, and the compiler's evaluator sign extends the result, regarding a set bit 7 as a negative sign bit... A rather weird compiler error, not a program error. > - Last warning: > > > mseactions.pas(762,34) Warning: (4110) Range check error while > > evaluating constants (-63489 must be between 0 and 65535) > >Point to: >result:= (key <> 0) and (key <> word(not modmask)); > >I propose this instead (see abs()): >result:= (key <> 0) and (key <> word(abs(not modmask))); > > What do you think? About the same as for the case above, Same analysis as above yields: -63489 = $07FF, word ($07FF) = 2047, NOT $07FF = $F800 = 63488. Here, a lot more bits are involved, but this may also derive from a masking or combining operation, setting the 16-bit-value "sign bit" (bit 15) and triggering a - false - sign extension by the compiler. It _may be_ that it's sufficient to just mask off any unused bits within the evaluation expression _before_ casting the result to the destination size. So foldlevelmask = byte(not (foldhiddenmask or currentfoldhiddenmask)); might become foldlevelmask = byte (not (foldhiddenmask or currentfoldhiddenmask) AND $FF); and result:= (key <> 0) and (key <> word(not modmask)); might become result:= (key <> 0) and (key <> word ((not modmask) AND $)); And yes, you wrote on Sun, 29 Mar 2020 09:37:10 -0700 (MST): > What is very strange is that I get also a warning with this (see abs() > added): > > const > foldhiddenbit = 7; ^ This is the place that could trigger such a sign extension. > foldhiddenmask = abs(1 shl foldhiddenbit); And it's even used indirectly to produce a value "of indeterminate size", and with indeterminate signedness above that. > currentfoldhiddenbit = 6; > currentfoldhiddenmask = abs(1 shl currentfoldhiddenbit); On the other hand, this sequence does not produce a borderline value, and thus won't trigger any unexpected (mis-) behaviour. I suspect a similar situation with the other warning. Should the second case _not_ arise from such a borderline situation, you might attempt to report a serious compiler error on the fpc bug tracker. (There's not any reason to regard every 4th bit as a sign bit! Bit 11, the probable culprit in the second case above, has no such function at all.) -- -- (Weitergabe von Adressdaten, Telefonnummern u.ä. ohne Zustimmung nicht gestattet, ebenso Zusendung von Werbung oder ähnlichem) --- Mit freundlichen Grüßen, S. Schicktanz --- ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
Hello fredvs, you wrote on Fri, 27 Mar 2020 18:30:11 -0700 (MST): > I can understand that in a case of the variable is part of the procedure, > like this: ... > begin > case b of // here warning > 1: writeln('hello'); > end > end; ... > But for this, when the variable is global: ... > Here, imho, the warning is not really needed. There's no difference between the cases - why should a global variable be regarded any different from a local one? Because it's initalized by the start up code? Well, it might at any point in the program before be modified, and thus fall outside the range of values the case statement covers, what is the _reason_ for the warning. Your declaration even defines a variable that's initialized to an illegal value in the first place, using it without prior assignment should produce a program failure! > It is the case in mostly all the warning of msegui, so, imho, we may > disable the warning in that case. No. You wrote on Fri, 27 Mar 2020 18:39:41 -0700 (MST): > > I propose to add a - possibly empty, but AT LEAST commented! - default > > (else) clause. If you see that this clause will _never_ cause a problem, it can be left alone and be disregarded (until it may be needed). Otherwise this clause should rather raise an exception, so _if_ an extraneous case occurs, it will show up and can be handled, and the reason noted. (That's one of the problems with heritage: what's that good for?) > Yes I was thinking to do that but it is **lot of work**, +- 500 cases to > fix, sometimes in complicated code. Working on Windows? But even there you can get those fine Unix utilities like grep, awk, sed and others that make it easy to take care of such things. Certainly that's some work on the outset, but you can cover 500 cases with the same effort as only 5 or 15. And have the tools (and skills) ready for other, similar cases. -- -- (Weitergabe von Adressdaten, Telefonnummern u.ä. ohne Zustimmung nicht gestattet, ebenso Zusendung von Werbung oder ähnlichem) --- Mit freundlichen Grüßen, S. Schicktanz --- ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk
Re: [MSEide-MSEgui-talk] About Warnings with mseide + fpc 3.0.4 / 3.2.0
Hello Seignard. > Yes I was thinking to do that but it is **lot of work**, +- 500 cases to > fix, sometimes in complicated code. It was terminated yesterday, after lot of cups of coffee, checking every case individually and following your advice: adding a last else statement + comment. > else; // added statement to make compiler happy. https://github.com/mse-org/mseide-msegui/commit/2da0695 About range check error: > > msedatalist.pas(891,18) Warning: (4110) Range check error while > > evaluating constants (-193 must be between 0 and 255) Many thanks for your explanations. It seems that the conclusion is, in this case, to use {$warn 6060 off} and dont touch to the original code. OK everybody to disable warn 6060 for those 2 cases? Fre;D -- Sent from: http://mseide-msegui-talk.13964.n8.nabble.com/ ___ mseide-msegui-talk mailing list mseide-msegui-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk