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: Wed, 08 Feb 2023 22:12:38 -0800 Organization: None to speak of Lines: 35 Message-ID: <87wn4rcqp5.fsf@nosuchdomain.example.com> References: <0mvDL.68810$b7Kc.34465@fx39.iad> <87r0v2ecc0.fsf@nosuchdomain.example.com> <87edr1e1js.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader01.eternal-september.org; posting-host="8191dc9d3cc9a723636202e99e75b43d"; logging-data="629235"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LMYc2gpgf6oe1t8xgSL0B" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:H0iKgvQKGLLo90OC7szfmHhvBQQ= sha1:cdy1kYyUQ7ffAC9UXAtS8ogpn2k= Xref: csiph.com comp.lang.c++:89055 comp.lang.c:169230 Blue-Maned_Hawk writes: > On 2/7/23 14:08, Keith Thompson wrote: >> Muttley@dastardlyhq.com writes: >>> On Mon, 06 Feb 2023 13:03:11 -0800 >>> Keith Thompson wrote: >> [...] >>>> C's grammar is not trivial to parse, due to typedefs. A typedef >>>> effectively creates a context-specific keyword, which means the parser >>>> has to interact with the symbol table. (Historically, this is because >>>> typedefs were introduced relatively late in the evolution of C.) >>> >>> Could it not cheat and simply treat a typedef as a kind of macro? >> No, typedefs have scope, and a declaration in an inner scope can >> hide a >> typedef in an outer scope. > > ​So could it treat it as a macro that gets `#undef`ed at the end of a scope? No, that wouldn't even work for the example I posted. The "macro" wouldn't be undefined until the end of main. #include int main(void) { typedef int Integer; { int Integer = 10; printf("Integer = %d\n", Integer); } // int Integer = 20; // would be a syntax error } -- 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 */