- Feb 17, 2002
- 4,723
- 80
- 91
I have two functions, X and Y. Function Y takes in a pointer to a struct. Function X calls function Y and passes a pointer to a struct through the parameters.
For some reason, no matter what, function Y receives the pointer as null. I can't figure this out.
Here's an example of what I'm talking about.... My actual code is actually very, very long, and it's really messy for the time being (since I'm messing with it trying to get it to work). I have no idea why this is happening. Any ideas?
Example:
void makeList()
{
int listLength;
List *myList = (List*)malloc(sizeof(List));
ListAdd(1, myList);
ListAdd(2, myList);
ListAdd(3, myList);
listLength = GetListLength(myList);
printf("List length: %d\n", listLength);
}
int GetListLength(List* L)
{
//The following line will get a segmentation fault because L is null...
//even though we passed a valid pointer to this function. WTF?!
return L->count;
}
For some reason, no matter what, function Y receives the pointer as null. I can't figure this out.
Here's an example of what I'm talking about.... My actual code is actually very, very long, and it's really messy for the time being (since I'm messing with it trying to get it to work). I have no idea why this is happening. Any ideas?
Example:
void makeList()
{
int listLength;
List *myList = (List*)malloc(sizeof(List));
ListAdd(1, myList);
ListAdd(2, myList);
ListAdd(3, myList);
listLength = GetListLength(myList);
printf("List length: %d\n", listLength);
}
int GetListLength(List* L)
{
//The following line will get a segmentation fault because L is null...
//even though we passed a valid pointer to this function. WTF?!
return L->count;
}
