Sunday, 11 August 2013

Is it safe to return file File descriptor locally allocated from another function In C

Is it safe to return file File descriptor locally allocated from another
function In C

#include <stdio.h>
#include <string.h>
FILE * BestTry();
int main()
{
char arr[] = "hello";
FILE * desc = BestTry();
fwrite(arr,1,5,desc);
fclose(desc);
}
FILE * BestTry()
{
FILE * retDesc = fopen(".\\hello.dat","w+");
return retDesc;
}
Is it is safe to use desc for any use because i am allocating memory to a
local variable in function BestTry. If it is safe then what is the reason
?

No comments:

Post a Comment