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


Groups > comp.lang.c > #148787

Re: K&R function definition with typedef parameter names

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: K&R function definition with typedef parameter names
Date 2020-01-05 04:00 +0000
Organization A noiseless patient Spider
Message-ID <87blrimu2f.fsf@bsb.me.uk> (permalink)
References <qurl9m$b69$1@gioia.aioe.org>

Show all headers | View raw


Steve Keller <keller@no.invalid> writes:

> I wonder if the old K&R style function definition allowed to use
> function parameter names that were already typedef'd.  Current
> compilers like gcc, clang, and tcc don't allow this:
>
>     typedef int t;
>     int fun(t)
>         int t;
>     {
>         return 0;
>     }
>
> The compilers I tested on this seem to interpret "int fun(t)" as a
> function declaration of fun that takes one argument of type t.  I
> don't have any pre C90 compiler available but would like to know how
> this would be handled.  If the above was possible in old pre-ANSI C
> this seems to have changed.

At least one pre-ANSI C compiler (pcc) accepts this code.

> Was it intentionally and is it stated
> explicitely anywhere?

ANSI C includes the wording:

  "An identifier declared as a typedef name shall not be redeclared as a
  parameter."

in 3.7.1.  The corresponding text in the reference manual at the end of
K&R1 is missing, so I think this was a deliberate change designed to
facilitate parsing of new-style function declarations and definitions.

-- 
Ben.

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