Path: csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: lvalue assignment difference between C and C++ Date: Mon, 06 Feb 2023 01:01:40 -0800 Organization: None to speak of Lines: 39 Message-ID: <87h6vzupzf.fsf@nosuchdomain.example.com> References: <0mvDL.68810$b7Kc.34465@fx39.iad> MIME-Version: 1.0 Content-Type: text/plain Injection-Info: reader01.eternal-september.org; posting-host="181ea74528ed435ea473c00f282e1c24"; logging-data="3173026"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+J8Tvg3zj1Z3V7zCLaC0rB" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:LftDJoUjZ4avWCe0QZKyvzH/EvI= sha1:yoKVwqZkF9K6IDwJfUKhinfzYx4= Xref: csiph.com comp.lang.c++:88984 comp.lang.c:169197 Paavo Helde writes: > 04.02.2023 18:59 Muttley@dastardlyhq.com kirjutas: [...] >> Ok, that makes sense. Though I wonder - given the main C compilers >> used now >> are also C++ compilers - why they don't just silently allow it in C? Would >> there be any wierd or unfortunate side effects in C if it was? > > This would basically introduce a limited notion of 'reference' in the > C language, which would make the language more complex to teach and > learn. That's the opposite to the goals C currently has. > > And yes, having a simpler language in general means the programs > written in it need to be more complex. Here it just means a couple of > extra asterisks and ampersands, so not a big deal. I agree it's not a big deal, and I've already commented on the idea that most C compilers are also C++ compilers (they aren't). But I don't think that allowing a conditional expression to be an lvalue would require introducing references into the language. An lvalue is defined as "an expression that potentially designated an object" ("potentially" because *ptr is still an lvalue even if ptr==NULL). This would just mean that `x ? y : z` would designate an object, and the identify of that object depends on the value of `x`. It's not all that much different from `a[i]`, where the identify of the object it designates depends on the values of `a` and `i` -- or `*p` for that matter. If it were introduced in a future edition of the C standard, I don't think it would cause many problems. (And the generated machine code would probably use pointers anyway.) But I don't think there's enough demand to justify it. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */