The following simplified program compiles and links perfectly.
Code: Select all
int alloc_worked_main = 0;
int alloc_worked_sub = 0;
void main()
{
char *ptr = NULL;
set_mem ( ptr );
if (ptr) alloc_worked_main = 1;
printf ("main=%s,\nsub=%s\n", alloc_worked_main, alloc_worked_sub);
}
char * set_mem ( char *ptr )
{
ptr = (char *) malloc ( 256 );
if (ptr) alloc_worked = 1;
return ptr;
}
It produces the following output...
main=0
sub=1
The pointer is NULL in main().
Why?