Function Call Function Loop

Feb 11, 2012 at 8:40pm
1
2
3
4
5
6
7
8
9
void A()
{
B()
}

void B()
{
A()
}


This will loop forever, is this good?

It just simplifies and isolates the segments of the program well as opposed to having a return to a main controller.
Feb 11, 2012 at 8:45pm
I'd rather use
1
2
3
4
5
6
7
8
9
10
int main()
{
    ...
    while(true)
    {
        ...
    }
    
    return 0;
}


It's shorter ^^ and you can also add some more source code. Or, if you want to, use void main() instead of int main()
Last edited on Feb 11, 2012 at 8:46pm
Feb 11, 2012 at 8:50pm
First of all, see FlashDrive's suggestion.

This will loop forever, is this good?

It will not compile because you forgot the semicolons ; after calling A() and B() inside the functions.
Secondly, it will eventually crash by stack overflow (each new call uses new memory).
http://en.wikipedia.org/wiki/Stack_overflow

Edit: used wrong tags.
Last edited on Feb 11, 2012 at 8:51pm
Feb 11, 2012 at 8:57pm
It's the same as you would write a batch file with the content <name of batch file>, isn't it?
Topic archived. No new replies allowed.