X
xianwei
Guys:
The problem come from a book
Data structures and Algorithm Analysis in C
First, some code in list.h
struct Node;
typedef struct Node Node;
typedef struct Node *PtrNode;
typedef PtrNode List;
another code in list.c
#define Error( Str ) FatalError( Str )
#define FatalError( Str ) fprintf( stderr, "%s\n", Str ), exit(1)
List
MakeEmpty( List L )
{
if (L != NULL)
{
DeleteList( L );
}
L = malloc( sizeof (struct Node) );
if (L == NULL)
{
FatalError( "Out of memory!" );
}
L->Next = NULL;
return L;
}
finally, the code is below: in testlist.c
List L;
L = MakeEmpty( NULL );
The book tell me, that can initialize L.
I don't know why *NULL* can be as a parameter in MakeEmpty()
In MakeEmpty(), L's address is zero(or NULL)
so like below
0 = malloc( sizeof (struct Node));
I think is too dangerous, someone tell me, In 16 bit system,
the system use real address, so the 0's address has been
cover BIOS data, In 32 bit system, use virtual address,
so safer than 16 bit system.
But I want to know
the above code is whether a good choice?
writting some code to 0's address.
thanks.
The problem come from a book
Data structures and Algorithm Analysis in C
First, some code in list.h
struct Node;
typedef struct Node Node;
typedef struct Node *PtrNode;
typedef PtrNode List;
another code in list.c
#define Error( Str ) FatalError( Str )
#define FatalError( Str ) fprintf( stderr, "%s\n", Str ), exit(1)
List
MakeEmpty( List L )
{
if (L != NULL)
{
DeleteList( L );
}
L = malloc( sizeof (struct Node) );
if (L == NULL)
{
FatalError( "Out of memory!" );
}
L->Next = NULL;
return L;
}
finally, the code is below: in testlist.c
List L;
L = MakeEmpty( NULL );
The book tell me, that can initialize L.
I don't know why *NULL* can be as a parameter in MakeEmpty()
In MakeEmpty(), L's address is zero(or NULL)
so like below
0 = malloc( sizeof (struct Node));
I think is too dangerous, someone tell me, In 16 bit system,
the system use real address, so the 0's address has been
cover BIOS data, In 32 bit system, use virtual address,
so safer than 16 bit system.
But I want to know
the above code is whether a good choice?
writting some code to 0's address.
thanks.