Path: csiph.com!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: How About Disallowing Assignments In Expressions? Date: Sat, 17 Feb 2024 16:45:49 -0800 Organization: None to speak of Lines: 34 Message-ID: <87ttm67g76.fsf@nosuchdomain.example.com> References: <87r0hlef8q.fsf@nosuchdomain.example.com> <87sf20o4e2.fsf@bsb.me.uk> <87a5o3amit.fsf@nosuchdomain.example.com> <20240214120232.00001d56@yahoo.com> <871q9f9go2.fsf@nosuchdomain.example.com> <867cj61ckn.fsf@linuxsc.com> <87bk8i8ci1.fsf@nosuchdomain.example.com> <86plwuy6n5.fsf@linuxsc.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="b18c3c7ac9146633dc598f0a8f97c261"; logging-data="718117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jN6Bj6BMze3g4nTeY+FN4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:OVx1wnj2OVP1imsEgaOY9F/pQv4= sha1:S7y2HChrYoWxWYbi+imubOW11P0= Xref: csiph.com comp.lang.c:382645 Tim Rentsch writes: > Keith Thompson writes: >> Tim Rentsch writes: >>> Keith Thompson writes: >> [...] >> >>>> In this particular case, I'd just use 0. If for some reason I >>>> needed to make it explicitly of type uint64_t (say, for an >>>> argument to a variadic function), I'd write `(uint64_t)0`. >>> >>> Ick. At least write '(uint64_t){ 0 }' rather than casting. >> >> Why? > > Casts are dangerous. Besides being dangerous, in many cases > casts are accidents waiting to happen. Writing casts at the drop > of a hat is a bad habit. A good programming practice is to avoid > using a cast whenever feasible. Using a compound literal isn't a > lot better than just a raw cast, but it does at least provide a > little extra safety because it allows only "safe" conversions. > Seeing a cast in open code should always raise a red flag, > especially when, as in this case, it's easy to find a safer > alternative. I disagree in this case. Yes, casts certainly can be dangerous, especially those involving pointers, and I'd say that all casts should be looked on with some suspicion. But anyone who knows C can recognize that casting a constant 0 to an integer type is not in any way dangerous. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */