From kevinfishburne at ...590... Thu Sep 1 08:42:53 2011 From: kevinfishburne at ...590... (Kevin Fishburne) Date: Thu, 01 Sep 2011 02:42:53 -0400 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables Message-ID: <4E5F296D.2090304@...590...> Holy shit something is seriously wrong with a recent commit. All my loops are going infinitely by wrapping around to negative values. Guess no one's using the most recent build or they'd have noticed. Try something like this in a module with no other code: ' Gambas module file Public Sub Main() Dim Counter As Short For Counter = 0 To 32767 Print Counter Next End -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sales at ...590... phone: (770) 853-6271 From gambas at ...1... Thu Sep 1 13:35:04 2011 From: gambas at ...1... (=?utf-8?q?Beno=C3=AEt_Minisini?=) Date: Thu, 1 Sep 2011 13:35:04 +0200 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <4E5F296D.2090304@...590...> References: <4E5F296D.2090304@...590...> Message-ID: <201109011335.04889.gambas@...1...> > Holy shit something is seriously wrong with a recent commit. All my > loops are going infinitely by wrapping around to negative values. Guess > no one's using the most recent build or they'd have noticed. Try > something like this in a module with no other code: > > ' Gambas module file > > Public Sub Main() > > Dim Counter As Short > > For Counter = 0 To 32767 > Print Counter > Next > > End There was a bug fix in loop management. And your loop must loop indefinitely, because a short value wraps to -32768 after 32767, so the limit is never passed. The solution is not using a Short as loop variable. Regards, -- Beno?t Minisini From kevinfishburne at ...590... Thu Sep 1 23:00:15 2011 From: kevinfishburne at ...590... (Kevin Fishburne) Date: Thu, 01 Sep 2011 17:00:15 -0400 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <201109011335.04889.gambas@...1...> References: <4E5F296D.2090304@...590...> <201109011335.04889.gambas@...1...> Message-ID: <4E5FF25F.80308@...590...> On 09/01/2011 07:35 AM, Beno?t Minisini wrote: >> Holy shit something is seriously wrong with a recent commit. All my >> loops are going infinitely by wrapping around to negative values. Guess >> no one's using the most recent build or they'd have noticed. Try >> something like this in a module with no other code: >> >> ' Gambas module file >> >> Public Sub Main() >> >> Dim Counter As Short >> >> For Counter = 0 To 32767 >> Print Counter >> Next >> >> End > There was a bug fix in loop management. > > And your loop must loop indefinitely, because a short value wraps to -32768 > after 32767, so the limit is never passed. > > The solution is not using a Short as loop variable. I understand what it's doing now. The "final" Next overflows the counter, making the loop infinite. While that makes sense, something doesn't quite smell right. I presume this behavior goes for any integer type, such as Byte, Integer, Long, etc.? -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sales at ...590... phone: (770) 853-6271 From gambas at ...1... Thu Sep 1 23:01:55 2011 From: gambas at ...1... (=?utf-8?q?Beno=C3=AEt_Minisini?=) Date: Thu, 1 Sep 2011 23:01:55 +0200 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <4E5FF25F.80308@...590...> References: <4E5F296D.2090304@...590...> <201109011335.04889.gambas@...1...> <4E5FF25F.80308@...590...> Message-ID: <201109012301.55522.gambas@...1...> > On 09/01/2011 07:35 AM, Beno?t Minisini wrote: > >> Holy shit something is seriously wrong with a recent commit. All my > >> loops are going infinitely by wrapping around to negative values. Guess > >> no one's using the most recent build or they'd have noticed. Try > >> something like this in a module with no other code: > >> > >> ' Gambas module file > >> > >> Public Sub Main() > >> > >> Dim Counter As Short > >> > >> For Counter = 0 To 32767 > >> > >> Print Counter > >> > >> Next > >> > >> End > > > > There was a bug fix in loop management. > > > > And your loop must loop indefinitely, because a short value wraps to > > -32768 after 32767, so the limit is never passed. > > > > The solution is not using a Short as loop variable. > > I understand what it's doing now. The "final" Next overflows the > counter, making the loop infinite. While that makes sense, something > doesn't quite smell right. I presume this behavior goes for any integer > type, such as Byte, Integer, Long, etc.? Of course. -- Beno?t Minisini From kevinfishburne at ...590... Thu Sep 1 23:23:34 2011 From: kevinfishburne at ...590... (Kevin Fishburne) Date: Thu, 01 Sep 2011 17:23:34 -0400 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <201109012301.55522.gambas@...1...> References: <4E5F296D.2090304@...590...> <201109011335.04889.gambas@...1...> <4E5FF25F.80308@...590...> <201109012301.55522.gambas@...1...> Message-ID: <4E5FF7D6.3030104@...590...> On 09/01/2011 05:01 PM, Beno?t Minisini wrote: >> On 09/01/2011 07:35 AM, Beno?t Minisini wrote: >>>> Holy shit something is seriously wrong with a recent commit. All my >>>> loops are going infinitely by wrapping around to negative values. Guess >>>> no one's using the most recent build or they'd have noticed. Try >>>> something like this in a module with no other code: >>>> >>>> ' Gambas module file >>>> >>>> Public Sub Main() >>>> >>>> Dim Counter As Short >>>> >>>> For Counter = 0 To 32767 >>>> >>>> Print Counter >>>> >>>> Next >>>> >>>> End >>> There was a bug fix in loop management. >>> >>> And your loop must loop indefinitely, because a short value wraps to >>> -32768 after 32767, so the limit is never passed. >>> >>> The solution is not using a Short as loop variable. >> I understand what it's doing now. The "final" Next overflows the >> counter, making the loop infinite. While that makes sense, something >> doesn't quite smell right. I presume this behavior goes for any integer >> type, such as Byte, Integer, Long, etc.? > Of course. Would be nicer if it simply halted execution with an overflow error. Silent overflow could be used as a feature, but if it was unintentional it would be hard to find the error in logic if you didn't realize what was happening. The program would keep running but behave unexpectedly. Are people actually using this as a feature by intentionally overflowing variables? -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sales at ...590... phone: (770) 853-6271 From gambas at ...1... Thu Sep 1 23:28:07 2011 From: gambas at ...1... (=?utf-8?q?Beno=C3=AEt_Minisini?=) Date: Thu, 1 Sep 2011 23:28:07 +0200 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <4E5FF7D6.3030104@...590...> References: <4E5F296D.2090304@...590...> <201109012301.55522.gambas@...1...> <4E5FF7D6.3030104@...590...> Message-ID: <201109012328.07098.gambas@...1...> > > Would be nicer if it simply halted execution with an overflow error. > Silent overflow could be used as a feature, but if it was unintentional > it would be hard to find the error in logic if you didn't realize what > was happening. The program would keep running but behave unexpectedly. > Are people actually using this as a feature by intentionally overflowing > variables? I can't detect overflow in C fast enough. Doing that will slow down the interpreter a lot. -- Beno?t Minisini From kevinfishburne at ...590... Fri Sep 2 00:14:06 2011 From: kevinfishburne at ...590... (Kevin Fishburne) Date: Thu, 01 Sep 2011 18:14:06 -0400 Subject: [Gambas-devel] gb3: recent revision regarding FOR...NEXT loops and counter variables In-Reply-To: <201109012328.07098.gambas@...1...> References: <4E5F296D.2090304@...590...> <201109012301.55522.gambas@...1...> <4E5FF7D6.3030104@...590...> <201109012328.07098.gambas@...1...> Message-ID: <4E6003AE.8090101@...590...> On 09/01/2011 05:28 PM, Beno?t Minisini wrote: >> Would be nicer if it simply halted execution with an overflow error. >> Silent overflow could be used as a feature, but if it was unintentional >> it would be hard to find the error in logic if you didn't realize what >> was happening. The program would keep running but behave unexpectedly. >> Are people actually using this as a feature by intentionally overflowing >> variables? > I can't detect overflow in C fast enough. Doing that will slow down the > interpreter a lot. Understood. I'll update my code accordingly. The docs at http://gambasdoc.org/help/lang/for might want to mention this however, to lessen the gnashing of teeth when gb3 is released. -- Kevin Fishburne Eight Virtues www: http://sales.eightvirtues.com e-mail: sales at ...590... phone: (770) 853-6271