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: Mon, 12 Feb 2024 08:20:41 -0800 Organization: None to speak of Lines: 32 Message-ID: <87o7cl8xie.fsf@nosuchdomain.example.com> References: <87r0hlef8q.fsf@nosuchdomain.example.com> <87sf20o4e2.fsf@bsb.me.uk> <8734tzoli4.fsf@bsb.me.uk> <87v86vbx6s.fsf@nosuchdomain.example.com> <87il2vbvza.fsf@nosuchdomain.example.com> <87eddjblyh.fsf@nosuchdomain.example.com> <87bk8m9xzw.fsf@nosuchdomain.example.com> <874jee9wz1.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="dde32586fdbd978f355be701e1d622ad"; logging-data="1699122"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182YdZIKOOrCTW5yAs7424d" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:hY8pjztz+LzJx/GOCoR0p0zRhjk= sha1:gUhZSIJs3+SWukVKj4RG8NcuHO8= Xref: csiph.com comp.lang.c:382381 David Brown writes: [...] >>>> On 12/02/2024 11:26, David Brown wrote: [...] >>>>>      int * p; [...] >>>>>      _Bool b = p; [...] >>>>>      int x = p; [...] > Conversions of a pointer to "int" or to "_Bool" are both allowed by > the C standards. So a conforming C compiler has to accept them and > generate appropriate code for them. > > If the pointer's value cannot be represented in the target type when > converting to an integer type, then it is undefined behaviour - but > the compiler usually can't know that for sure at compile time. Thus > it has to generate code that accepts this and will work if the address > happens to be small enough. The compiler can, however, issue a > warning that the programmer is probably doing something silly. > > Conversion of any scaler (including pointers) to _Bool is done by > comparison to 0. And since that is often a sensible thing to do, > there is no warning in gcc - it would give too many false positives. Conversion of a pointer to int behaves as you describe, but cannot be done implicitly. A cast is required to avoid a constraint violation. -- 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 */