TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Dominique Curtis
from: William McBrine
date: 1998-10-26 02:26:58
subject: Re: malloc and the resulting file corruption...

-=> Dominique Curtis wrote to Tom Torfs <=-

 DC>  TT> You really should include , instead of 
 DC>  TT> providing your own prototype for malloc().
 DC> 
 DC> Actually, no..

Actually, yes. :-) You can't just change prototypes at will, and still
expect the program to work (or even compile).

 DC> I have to include my own declaration because I am allocating memory
 DC> for a character array..

The way to do that is to cast the return value of malloc(); i.e.:

 char *p;
 p = (char *) malloc(n);

 DC> When I comment it out, I run out of memory very quickly...

Huh?

 DC> the standard declaration for malloc would be void malloc() or
 DC> something...

 void *malloc(size_t);

i.e., it returns a pointer with no type. You give it a type by casting the
return value.

... Come and see the violence inherent in the system!
--- MultiMail/Linux v0.19
* Origin: COMM Port OS/2 juge.com 204.89.247.1 (281) 980-9671 (1:106/2000)
SEEN-BY: 396/1 632/0 371 633/260 267 270 371 634/397 635/506 728 810 639/252
SEEN-BY: 670/218
@PATH: 106/2000 396/1 633/260 635/506 728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.