Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!quiche!storm From: storm@cs.mcgill.ca (Marc WANDSCHNEIDER) Newsgroups: comp.lang.c Subject: Problems with malloc() Message-ID: <1991Apr1.171908.2198@cs.mcgill.ca> Date: 1 Apr 91 17:19:08 GMT Sender: news@cs.mcgill.ca (Netnews Administrator) Organization: SOCS, McGill University, Montreal, Canada Lines: 60 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@cs.mcgill.ca McGill University It's 11pm, do YOU Marc Wandschneider Montreal, CANADA know what time it is? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~