Path: csiph.com!1.us.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.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 18:07:59 -0800 Organization: None to speak of Lines: 31 Message-ID: <87le7i7ce8.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> <87ttm67g76.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: dont-email.me; posting-host="b18c3c7ac9146633dc598f0a8f97c261"; logging-data="757012"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+y7OSM70OjkChNrIgzEvS5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:xPRwcB1sR7zCJD5VnyT2d/tzh4M= sha1:i0owOhrLkvOMI/RdZymGcBATK8I= Xref: csiph.com comp.lang.c:382651 Janis Papanagnou writes: > On 18.02.2024 01:45, Keith Thompson wrote: >> [...] But anyone who knows C can recognize >> that casting a constant 0 to an integer type is not in any way >> dangerous. > > That's what I'd expect. Moreover... > > I recall that we had used the _specific literal constant_ 0 as a > "universal" constant to all integral types, floats, and pointers > without cast.[*] That was in the 1990's. Are there meanwhile any > restrictions on using 0 without cast? 0 is of type int. In most contexts, it will be implicitly converted to any scalar type -- which is why { 0 } is a valid initializer for any type (C23 will allow {}). The problem is contexts where that conversion doesn't occur. The most common is an argument to a variadic function; for example printf("%ld\n", 0) has undefined behavior. A less common case is a call to a function with an old-style non-prototype declaration. > [*] I anyway preferred '\0', 0.0, or a 'null' constant definition > for pointers. I presume you mean NULL (and C23 adds nullptr). But note that NULL requires a cast in some cases, like printf("%p\n", (void*)NULL); -- 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 */