Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (degenerate_762, AndrewAMD), 877 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
for loop special case broken #417064
02/07/13 23:46
02/07/13 23:46
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Hello Mr. Lotter,

there is an issue with the following snippet.
Code:
#include <acknex.h>

void main()
{
	for (; ; wait(1));
}


the compiler does not reject it (that's correct, it's valid c code) but as soon as the engine starts it gets stuck in an endless loop. The actual engine window never pops up, just the white starter window.


Always learn from history, to be sure you make the same mistakes again...
Re: for loop special case broken [Re: Uhrwerk] #417096
02/08/13 12:11
02/08/13 12:11
Joined: Dec 2008
Posts: 1,218
Germany
Rackscha Offline
Serious User
Rackscha  Offline
Serious User

Joined: Dec 2008
Posts: 1,218
Germany
Valid code is Valid code.
The compiler checks for valid code, not functionality.

the above is like:
Code:
while(true){wait(1);}



MY Website with news of my projects:
(for example my current
Muliplayer Bomberman,
GenesisPrecompiler for LiteC
and TileMaster, an easy to use Tile editor)
Sparetime-Development

Re: for loop special case broken [Re: Rackscha] #417099
02/08/13 13:02
02/08/13 13:02
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
It should be. But the engine freezes what leads to the conclusion that it isn't exactly the same thing.
I ran into this problem some time ago that the for-loop doesn't work like expected if you use wait.
My thoughts are that the compiler has a larger difference between a while-loop and a for-loop in assembler and so the wait(1) cannot return to the engine scheduler or something like that----


Visit my site: www.masterq32.de
Re: for loop special case broken [Re: MasterQ32] #417103
02/08/13 13:19
02/08/13 13:19
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The wait(1) is called, but does not delay. This is indeed a special case, as the wait() function is not fully C compliant.

It makes no difference if you try that in a while or for loop. wait() always belongs in the loop body. But we'll mention that in the manual.

Re: for loop special case broken [Re: jcl] #417104
02/08/13 13:23
02/08/13 13:23
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Why not fixing it?


Always learn from history, to be sure you make the same mistakes again...
Re: for loop special case broken [Re: Uhrwerk] #417105
02/08/13 13:29
02/08/13 13:29
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Because documenting it is easier laugh.

Re: for loop special case broken [Re: jcl] #417106
02/08/13 13:33
02/08/13 13:33
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
It's not easier. It's easier for you. For everybody else it is much more complicated.


Always learn from history, to be sure you make the same mistakes again...
Re: for loop special case broken [Re: Uhrwerk] #417110
02/08/13 14:01
02/08/13 14:01
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's only much more complicated for you. Not for everybody else.

I think our users mostly prefer implementing more new features over implementing more bizarre ways to call wait().

Re: for loop special case broken [Re: jcl] #417112
02/08/13 14:30
02/08/13 14:30
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
No, this is not about me. I know this bug now. I'll never do it again and even if I did I'd immediately know what's wrong with my code. This is for example about MasterQ32:
Quote:
I ran into this problem some time ago that the for-loop doesn't work like expected if you use wait.

I also don't think this the usage of a for loop is bizarre. While the sample I originally posted is clearly pointless there actually are applications where this kind of a for loop is very elegant:
Code:
for (my-frame = 0; ; wait(1))
    my->frame += time_step;

You're a very experienced software engineer, probably much more experienced than me. But I still don't think that you're doing yourself or anybody else a favor when mentioning bugs in the manual instead of fixing them.

I think your users do not prefer new features over correct software. If the new WED gets delayed one working day because of this bug being fixed most users will gladly accept this.

Once again: Your software, your decision. I hold you in high regard for caring about this great piece of software for such a long time. It's just that I simply don't get your point here.


Always learn from history, to be sure you make the same mistakes again...
Re: for loop special case broken [Re: Uhrwerk] #417114
02/08/13 15:00
02/08/13 15:00
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Fair enough. Let me explain our point of view:

wait() is not a normal C function. So there are many special cases where it can not be used like such a function. Some of those special cases can be shielded from the user with little effort, others with a lot effort, others not at all. For instance, there is no solution to call wait() from an external DLL.

No user in the last 8 years had the idea to put a wait() call inside the control statement of a loop. Nor had we. You just don't program in this way when you want clean code, even if it's valid C syntax. So I consider this a rather bizarre case with little meaning for practical programming.

"Fixing" it would require to re-write the for and while loop handling in the compiler for considering the special case of a wait() call. This would not only come at a cost of less new features, any special case handling like this also makes a program less stable and harder to maintain.

In fact we would put a lot of effort in ending up with a worse software than before.

I hope you understand our decision in such cases.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1