From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: malloc question - About output casting Date: 8 Jun 2000 10:24:22 GMT Organization: Aachen University of Technology (RWTH) Lines: 29 Message-ID: <8hns8m$bvh$1@nets3.rz.RWTH-Aachen.DE> References: <393EFFB8 DOT 2D5AA7BB AT fujixerox DOT co DOT jp> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 960459862 12273 137.226.32.75 (8 Jun 2000 10:24:22 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 8 Jun 2000 10:24:22 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Burgupalli Chaitanya wrote: > But there was a mailing list thread where in it was recomended that > it is better not do that. ... and by coincidence, the problem you describe is _exactly_ the one that is the key argument against malloc() casting. You've been brushing a potential problem under the carpet by casting, which now surfaces as you removed the casts: > main.c:34: warning: assignment makes pointer from integer without a > cast This is the telltale sign of a forgotten #include . This warning is somewhat serious, but with the cast in place, you wouldn't have gotten it. Casts between pointer types should be needed only *very* rarely, in a properly written C program. Whenever you catch yourself writing one, it's best to sit back and re-think your current strategy: chances are you're just doing something silly or evil. About the only exceptions from this rule are arguments to variadic functions (like printf()) that have to be casted to (void *), and casts back from void* to some other type needed with calls through generalized function pointers like the qsort() comparison function. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.