Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: My C program does not compile or gives segmentation fault Date: Mon, 03 Apr 2017 12:10:48 -0700 Organization: None to speak of Lines: 37 Message-ID: References: <89549322-236e-4a59-9bb5-dc881593a846@googlegroups.com> <1b1stnc1vj.fsf@pfeifferfamily.net> <1bshm3akop.fsf@pfeifferfamily.net> <58d6dd90.19321421@news.xs4all.nl> <711f4140-eac3-4c0f-95e9-e1e083ec82df@googlegroups.com> <58e28868.10501859@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="f2c9bfded0050c613c6d03fc3a3590e5"; logging-data="31462"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gTOw2cLtmeVbH072b6DpM" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zhoK9JXYxXg87pQM+F7BBKTMcqo= sha1:Vj4wX6ignYN/M+hy9f0OGb8jyXA= Xref: csiph.com comp.lang.c:107690 supercat@casperkitty.com writes: > On Monday, April 3, 2017 at 12:39:07 PM UTC-5, Richard Bos wrote: >> supercat wrote: >> > In some application fields, code using pointer aliasing techniques >> >> That is not what casting malloc() is about, so stop trying to force your >> pseudo-1970s bat out of your belfry and into this thread. > > Who said anything about casting malloc? That's what this thread was about. Three articles directly upthread from your response, Richard Bos wrote: No, the real danger in superfluous casts is that they make the programmer think "oh, yawn, another cast, probably another malloc() call written by a C++ programmer - just ignore it", when what he _should_ think on seeing a cast is "Whoop! Whoop! Red alert! Someone is doing something unusual with the type system! Better be extra certain that what happens here is correct." Note that assigning the void * you get from malloc() to any other type of object pointer is _not_ something unusual with the type system, does _not_ need more attention than any other assignment, and therefore does not warrant the cast. Putting a cast there means depreciating the warning value of all appropriate casts. _That_ is the danger: not in the code, but in the mind of the programmer. Stop the brain rot. Do not cast malloc(). You can verify this yourself if your newsreader lets you view the parent of an article. Please do so. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"