Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #169229

Re: lvalue assignment difference between C and C++

From James Kuyper <jameskuyper@alumni.caltech.edu>
Newsgroups comp.lang.c, comp.lang.c++
Subject Re: lvalue assignment difference between C and C++
Date 2023-02-08 22:53 -0500
Organization A noiseless patient Spider
Message-ID <ts1qo8$hoct$1@dont-email.me> (permalink)
References (4 earlier) <trqh4c$31588$1@dont-email.me> <87r0v2ecc0.fsf@nosuchdomain.example.com> <trt5cs$3gvt8$1@dont-email.me> <87edr1e1js.fsf@nosuchdomain.example.com> <ts1ocr$hffi$1@bluemanedhawk.eternal-september.org>

Cross-posted to 2 groups.

Show all headers | View raw


On 2/8/23 22:13, Blue-Maned_Hawk wrote:
> On 2/7/23 14:08, Keith Thompson wrote:
>> Muttley@dastardlyhq.com writes:
>>> On Mon, 06 Feb 2023 13:03:11 -0800
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> 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?

The same identifier can be two different typedefs in two different
nested scopes. The typedef in the inner scope hides the typedef in the
outer scope, but the typedef in the outer scope becomes visible again at
the end of the inner scope. Therefore, you'd have to have an #undef at
the end of the inner scope immediately followed by a #define.

Note: macro replacement occurs during translation phase 4. Scopes don't
even exist until translation phase 7, and can be affected by some of the
transformations that can occur during translation phase 4. That is to
say, conditional compilation, #include directives or the expansion of a
macro could create or eliminate scopes that would not have been
identified as such in the code as it existed prior to translation phase 4.

Basically, to do something similar to what you're suggesting, you need
to first perform all phase 4, 5, and 6 transformations properly, then
start translation phase 7 parsing to identify where scopes start and
end. Then you have to insert #define and #undef directives in the
appropriate places to implement typedefs, and carry out a
mini-translation phase 4 limited to recognizing those #define and #undef
directives. I don't think that this late phase 4 processing would have
any significant advantage over just biting the bullet and implementing
typedefs correctly during translation phase 7.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 15:30 +0000
  Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 11:04 -0500
    Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 16:59 +0000
      Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 13:02 -0500
      Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-04 12:45 -0800
      Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-05 11:42 +0100
        Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 09:26 +0000
          Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 14:13 +0100
            Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 15:50 +0000
              Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 20:08 +0100
              Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:47 -0800
          Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 13:03 -0800
            Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-07 09:24 +0000
              Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-07 11:08 -0800
                Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-08 09:23 +0000
                Re: lvalue assignment difference between C and C++ Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-02-08 22:13 -0500
                Re: lvalue assignment difference between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-08 22:53 -0500
                Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 22:12 -0800
              Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 02:52 +0000
      Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-06 09:11 +0200
        Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 01:01 -0800
          Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-06 07:42 -0500
            Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:59 -0800
        Re: lvalue assignment difference between C and C++ bart c <bart4858@gmail.com> - 2023-02-06 08:11 -0800
          Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-06 21:19 +0000
        Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-07 07:44 +0100
          Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 09:18 +0200
    Re: lvalue assignment difference between C and C++ Kaz Kylheku <864-117-4973@kylheku.com> - 2023-02-06 22:21 +0000
      Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 14:43 -0800
        Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-07 03:17 -0800
          Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-07 16:25 +0000
            Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-08 13:19 -0800
              Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 23:46 +0000
  Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-04 19:41 +0100
  Re: lvalue assignment difference between C and C++ Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-02-10 16:19 -0800

csiph-web