Quote:
FILE *got_file(char *str)
{
FILE *fp = fopen(str, "r");
return fp;
}
will this be OK? the fp is a pointer points to FILE struct which stores in stack, I think. Any problems here?
This is OK. The
FILE
struct is NOT (a temporary) on the stack, its pointer is (but the pointer value, that is the address is copied as return value).
Quote:
char *got_str1()
{
static char *test = "a test";
return test;
}
Yes, it is OK, static variables are not temporaries.
Quote:
static char *got_str2()
{
char *test = "a test";
return test;
}
will this OK?
Ugly as it stands (I won't use it, if you ask me), it
should be OK too. Because string literals are not temporaries.