Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "Why the C Language Will Never Stop You from Making Mistakes" by JeanHeyd Meneide Date: Sun, 16 Aug 2020 10:50:17 -0700 Organization: None to speak of Lines: 34 Message-ID: <87wo1yeazq.fsf@nosuchdomain.example.com> References: <877du33by4.fsf@nosuchdomain.example.com> <87r1sb1fu5.fsf@nosuchdomain.example.com> <87k0y312ua.fsf@nosuchdomain.example.com> <88804d79-6f6f-427a-ae42-33fb0d07dd9ao@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="0c763dcea4bade25e66f8f642b4cd05d"; logging-data="19543"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2KJ/mTJQsGiHsZ8Um83sa" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:43HxaPzKwUn9jaG/JSOx1F710LQ= sha1:BYgr26DwJCdHH98GfuOfFt0e4qk= Xref: csiph.com comp.lang.c:153673 Richard Damon writes: [...] > Again, the want to remove the cast comes from C90 mindsets, and poorly > segmented code. Starting with C99, best practices was to try to > initialize things as soon as they were created, and initialization is > the most type sensitive part of a program, so it is best if the type was > mentioned in that section of code. Yes, one of the reasons to prefer the castless version became (somewhat) obsolete with C99's removal of implicit int. > Again, what HARM does the cast impose (particularly if hidden behind a > well named macro that avoids the repetition.) My main objection to using a cast is conceptual. A pointer cast in C is too unrestrained. I can be used to (try to) reinterpret memory of some time as if it were of a completely different type, perhaps with arbitrary bad results. The fact that the same syntax is used for a harmless and save conversion means that when I see a cast, particularly a pointer cast, I have to convince myself that it's safe. And in this case it's simply unnecessary. int *p = (void*)malloc(sizeof (int)); uint32_t n = (uint32_t)42; Both casts are equally "safe" -- and equally unnecessary. And I find the code simpler and easier to read without them. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */