Calling this function will not cause a "stack overflow". You can only cause a stack overflow by a function calling itself recursively. I'll explain briefly:
When you call a function in a program, it creates a new entry on the "call stack". This contains a little information about the current function, the place it was called from, and the local variables of the function. This entry, as I said, is created when you call the function, but when you return from the function, throw an exception, or simply let the function reach its end, the system uses that information to return to the previous point of execution, then removes that entry from the call stack.
So, before you call your function, you might have on the stack:
. .
. .
. .
| |
+---------------------------+
| performComplexOperation() |
| return address |
| local variables |
| ... |
+---------------------------+
then, you call the LogString
function:
. .
. .
. .
| |
+---------------------------+
| performComplexOperation() |
| return address |
| local variables |
| ... |
+---------------------------+
| LogString() |
| return address |
| local variables |
| ... |
+---------------------------+
But after LogString
completes, the code will return to performComplexOperation
using the return address. The entry for LogString will be removed:
. .
. .
. .
| |
+---------------------------+
| performComplexOperation() |
| return address |
| local variables |
| ... |
+---------------------------+
(this is where
LogString used to be)
In a stack overflow, the space taken by the entries on the stack will exceed the space alloted for the stack by the language you're using*, and the program won't be able to create the entry for the function you're about to call.
* Not exactly, but close enough.