Problems with malloc()
Marc WANDSCHNEIDER
storm at cs.mcgill.ca
Tue Apr 2 03:19:08 AEST 1991
I have written a program in an attempt to impliment queues in ANSI C. How-
ever, I have run into a few problems. My compiler at home (TC++ 1.0)
behaves INCREDIBLY strangely with the following pieces of code:
m,m1...m5 are all pointers to a struct of type Message (ie, they're type Link)
msgalloc() returns a type Link, and is sort of taken from the prototype given
on page 146 of K & R 2nd ed.
m1 = msgalloc();
messagemakenull(m1);
m1->source = 7;
m1->dest = 1;
m1->sent = 1.0;
m2 = msgalloc();
messagemakenull(m2);
m2->source = 6;
m2->dest = 2;
m2->sent = 2.0;
etc...
m4 = msgallloc(); /* <--- WARNING 1 (see below) */
messagemakenull(m4);
m4->source = 4;
m4->dest = 8;
m4->sent = 4.0;
Link msgalloc(void)
{
return (Message *) malloc(sizeof(Message));
}
void messagemakenull(Link makemenull)
{
makemenull->next = NULL;
makemenull->source = 0;
makemenull->dest = 0;
makemenull->sent = 0;
}
Now, the problem is, TC++ 1.0 will compile this when I run it from the DOS
prompt, but will give me the warning NON-PORTABLE FUNCTION CONVERSION IN
MAIN at the line m4 = msgalloc(); as indicated above.
However, when I choose BUILD ALL it under the IDE of TC, it SOMETIMES
generates the same line as an ERROR, but it always generates a LINK ERROR
which states UNDEFINED SYMBOL _MSGALLOC IN MODULE QUEUES.C.
Can somebody please tell me what the *%*&^ is going on. All I really want
to do is something similar to the NEW(pointer to type X) in PASCAL....
Any help would save my hair.
./*-
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
storm at cs.mcgill.ca McGill University It's 11pm, do YOU
Marc Wandschneider Montreal, CANADA know what time it is?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Comp.lang.c
mailing list