Hello,
I've seen in some programs that they provide functions which has the
following prototype:
char *func1();
However I'm not sure it's safe. If the char array beeing returned is a local
variable such as:
char *func1()
{
char string[] = "Hello World";
return string;
}
then you got a problem because the string will be stored on stack which will
be de-allocated upon function return. So in reality the string is located on
a memory position which is availble for anyones use.
If keywords such as static or global data is returned the situation might be
different.
If you use new/malloc on the data you want to return it's safe but then
again you're making a memory leak unless the caller knows it's nessecary to
clean up.
Could anyone clear this up for me.
Thanks in advance.
-- John