Function Call Function Loop

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.
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
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
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.