їRecursion?
#1

Why if i script this:

Code:
forward Test();
public Test()
{
    new Random;
    Random = random(1);
    if(Random == 0) return Test();
    return 1;
}
I get this warning:
warning: recursion in Test

Shall i worry about that? or it's simplily a normal warning to the writer?

Thaks!
Reply
#2

Because recursion is when you recall the function inside itself.

You're creating an infinite loop which might freeze your server until it reaches an end point or you close the server successfully.

Shall you be worried about it? pretty much, if you don't stop it correctly.
Reply
#3

So if i had bad luck, and the function always returns inside itself(in case of that code for example) because of the random value.. my server can crash. Ok...



Thank you a lot!
Reply
#4

Quote:
Originally Posted by ByMatt20030
View Post
So if i had bad luck, and the function always returns inside itself(in case of that code for example) because of the random value.. my server can crash. Ok...



Thank you a lot!
Not because of the random value...
Code:
    if(Random == 0) return Test();
Quote:
Originally Posted by Kaperstone
View Post
You're creating an infinite loop which might freeze your server until it reaches an end point or you close the server successfully.
The return Test(); part does create this infinite loop kaperstone is talking about.
Reply
#5

i compiled that, i didn't get any warning xD
Reply
#6

Code:
randomEx(max, exception)
{
	new rand = random(max);
	while(rand == exception)
	{
		rand = random(max);
	}
	return rand;
}
Be careful, don't make an infinite loop
Reply
#7

Quote:
Originally Posted by Y_Less
View Post
This is a non-warning added in certain versions of the compiler and not a problem.
How can we have a different version of compiler by using the same archive ?


i have test this :


Code:
func()
{
	called++;
	printf("called %d times.", called);
	return func();
}
result is :
[13:15:18] called 1358 times.
[13:15:18] Script[gamemodes/bare.amx]: Run time error 3: "Stack/heap collision (insufficient stack size)"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)