Path: utzoo!mnetor!uunet!mcvax!ukc!stc!datlog!slxsys!jpp From: jpp@slxsys.specialix.co.uk (John Pettitt) Newsgroups: comp.unix.xenix Subject: Re: memory allocation i.e. malloc Message-ID: <118@slxsys.specialix.co.uk> Date: 18 Dec 87 20:17:31 GMT References: <2866@sdsu.UUCP> Reply-To: jpp@slxsys.UUCP (John Pettitt) Organization: Specialix International, London, UK. Lines: 40 Keywords: malloc memory allocation core dump segment violation In article <2866@sdsu.UUCP> gold@sdsu.UUCP (Dan Gold) writes: >I having a problem allocating memory with malloc. >the problem is malloc returns negative when the address is > 32K. >I tried the following code: >#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]); > } >} malloc returns a pointer - you are asking printf to print a long int and a signed one at that ! Pointers don't have a sign, there is no problem with malloc - just the printf doing what you told it to do. P.S. pointers are 16 bit unless you use the -M flag to say otherwise and they are ALWAYS unsigned I A M A L O N G M S G -- John Pettitt UUCP :{backbone}!mcvax!ukc!pyrltd!slxsys!jpp Specialix Systems Domain :jpp%slxsys@pyra.co.uk London, UK. (Where else ? :-) Voice : +44 1 398 9422 (GMT) rn: core dumped