Path: utzoo!utgpu!water!watmath!clyde!rutgers!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.xenix Subject: Re: memory allocation i.e. malloc Summary: Try declaring malloc as (char *) rather than (int) Keywords: malloc memory allocation core dump segment violation Message-ID: <9808@mimsy.UUCP> Date: 16 Dec 87 02:47:43 GMT References: <2866@sdsu.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 25 In article <2866@sdsu.UUCP>, gold@sdsu.UUCP (Dan Gold) writes: -#include-struct message { - char foo[260]; -} *msgs[900]; - -main() -{ - int i; - for (i=0;i < 900;i++) - { - msg[i]=(struct message *)malloc(sizeof(struct message)); - printf("i= %d, msg[i] = %ld\n",i,msg[i]); - } -} By calling malloc without first declaring it, you implicitly declare it (int). (Shades of FORTRAN!) Try putting in a char *malloc(); somewhere before the first call. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris