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


Groups > comp.lang.c > #148883

Re: K&R function definition with typedef parameter names

From Steve Keller <keller@no.invalid>
Newsgroups comp.lang.c
Subject Re: K&R function definition with typedef parameter names
Date 2020-01-09 06:27 -0800
Organization Aioe.org NNTP Server
Message-ID <qv7d8g$1ofr$1@gioia.aioe.org> (permalink)
References <qurl9m$b69$1@gioia.aioe.org> <qurnsf$94r$1@dont-email.me>

Show all headers | View raw


James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> >     typedef int t;
> >     int fun(t)
> 
> In K&R C, t could not be a type, it could only be the identifier for a
> function parameter, so the issue never came up.

Yes, that's what I have assumed and what causes the difference between
K&R and standard C.

> In standard C, when function prototypes were added, the ambiguity you've
> run into became an issue. The committee produced a rule to deal with
> such cases: "If, in a parameter declaration, an identifier can be
> treated either as a typedef name or as a parameter name, it shall be
> taken as a typedef name."  (6.7. 5.3p10).
> 
> They had to deal with the ambiguity some way, and if they had made the
> opposite choice, to always resolve the ambiguity in favor of it being a
> parameter name, it would not have been possible to use a typedef name to
> declare a parameter of that type in a function prototype.

Yes, and the only alternative would be completely unacceptable,
i.e. to lookahead or shift tokens until the end of the function
declarator just to see if the following token is a ';' (making it a
function declaration and the 't' a typedef-name) or if the following
token is a type-name (making it an old-style function definition and
the 't' an identifier).

Steve

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


Thread

K&R function definition with typedef parameter names Steve Keller <keller@no.invalid> - 2020-01-04 19:31 -0800
  Re: K&R function definition with typedef parameter names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-05 04:00 +0000
    Re: K&R function definition with typedef parameter names Steve Keller <keller@no.invalid> - 2020-01-09 06:26 -0800
  Re: K&R function definition with typedef parameter names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-04 23:15 -0500
    Re: K&R function definition with typedef parameter names Steve Keller <keller@no.invalid> - 2020-01-09 06:27 -0800
  Re: K&R function definition with typedef parameter names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-05 06:47 +0100
    Re: K&R function definition with typedef parameter names Steve Keller <keller@no.invalid> - 2020-01-09 06:25 -0800
      Re: K&R function definition with typedef parameter names Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-09 16:22 +0100
        Re: K&R function definition with typedef parameter names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-09 08:20 -0800
          Re: K&R function definition with typedef parameter names Thiago Adams <thiago.adams@gmail.com> - 2020-01-09 10:49 -0800
            Re: K&R function definition with typedef parameter names David Brown <david.brown@hesbynett.no> - 2020-01-10 10:22 +0100
              Re: K&R function definition with typedef parameter names Ben Bacarisse <ben.usenet@bsb.me.uk> - 2020-01-10 13:05 +0000
                Re: K&R function definition with typedef parameter names David Brown <david.brown@hesbynett.no> - 2020-01-10 16:14 +0100
                Re: K&R function definition with typedef parameter names Richard Damon <Richard@Damon-Family.org> - 2020-01-10 11:15 -0500
                Re: K&R function definition with typedef parameter names James Kuyper <jameskuyper@alumni.caltech.edu> - 2020-01-10 20:51 -0500
              Re: K&R function definition with typedef parameter names Thiago Adams <thiago.adams@gmail.com> - 2020-01-10 06:24 -0800
                Re: K&R function definition with typedef parameter names David Brown <david.brown@hesbynett.no> - 2020-01-10 16:26 +0100
          Re: K&R function definition with typedef parameter names Nick Bowler <nbowler@draconx.ca> - 2020-01-13 22:12 +0000
  Re: K&R function definition with typedef parameter names Autist <autist69@gmail.com> - 2020-01-10 16:42 +0100
  Re: K&R function definition with typedef parameter names Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-01-11 09:56 -0800

csiph-web