#: 18510 S12/OS9/68000 (OSK)
06-Aug-93 16:59:49
Sb: #malloc() problem
Fm: David George 72240,134
To: ALL
I've got a weird one for someone. It concerns malloc() (no surprise right?).
I have used malloc() a lot and it works ok in most of my programs, but...
In this certain program malloc() doesn't malloc.
Here is a code segment:
char *ptr;
if ((ptr = (char *)malloc(sizeof(char)*80)) == NULL) {
fprintf(stderr, "can't malloc 80 bytes\n");
exit(ERROR);
}
If I print the address of ptr before the call to malloc and after malloc,
the address is the same. In all of my other programs where this works,
the address is different (as it should be). You would think that if the
malloc failed it would return NULL (at least the docs say say).
I have also replaced NULL with (char *) 0. I have also written it this way:
ptr = (char *)malloc(sizeof(char)*80);
if (ptr == NULL) {
.
.
}
I have tried it without the (char *) in front of malloc() and I have also
put char *malloc(); in beginning of code.
Has anyone run across this problem?
David George
There is 1 Reply.
|