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


Groups > comp.lang.c > #389511

Re: question about linker

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: question about linker
Date 2024-12-07 15:50 -0800
Organization None to speak of
Message-ID <875xnvxdcm.fsf@nosuchdomain.example.com> (permalink)
References (16 earlier) <vj22ce$37g4b$1@dont-email.me> <vj263c$396ln$1@dont-email.me> <vj2d21$3aqf3$1@dont-email.me> <vj2e34$3b1j8$1@dont-email.me> <87msh7xf19.fsf@bsb.me.uk>

Show all headers | View raw


Ben Bacarisse <ben@bsb.me.uk> writes:
[...]
> I've always wondered why prototypes in C did not simply use the existing
> syntax for declarations.  After all, it was right there in K&R C, just
> outside the parentheses:
>
> f(m, n, s)
> int m, n;
> char *s;
> { ... }
>
> could have become
>
> f(int m, n; char *s)
> { ... }
>
> rather than
>
> f(int m, int n, char *s)
> { ... }
>
> Does anyone know if there even /was/ a reason?

The ANSI C Rationale doesn't provide any illumination on this point.

Function prototypes were borrowed from C++, as I recall, so it might
be mentioned in Stroustrup's "The Design and Evolution of C++".
(I have a paper copy, but it's inaccessible.)

For consistency with existing declaration syntax, there should
probably be a semicolon after each declaration, including the
last one:

    void func(int arg;);

but an exception to omit the semicolon before the ")" would not have
been unreasonable.  (Struct members follow declaration syntax more
closely, but unlike function declarations they're commonly written on
multiple lines and they're enclosed in {} rather than ().)

One weak argument for the existing syntax is that the use of commas
between parameter declarations mirrors the use of commas between
arguments in a call.

But functions with multiple parameters of the same type aren't so
common that allowing them to be grouped would be all that much of
an advantage.  And the syntax wouldn't match exactly anyway, since
many kinds of declarations aren't allowed within in a prototype
and parameter declarations can't have initializers.  (Though the
latter could be used for default values.)

And even in ordinary declarations, a common style guideline is to
use a single declaration for each declared entity, for example
    int a;
    int b;
rather than
    int a, b;
or especially
    int x;
    int *y;
rather than
    int x, *y;

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

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


Thread

Re: question about linker David Brown <david.brown@hesbynett.no> - 2024-12-06 16:41 +0100
  Re: question about linker Bart <bc@freeuk.com> - 2024-12-06 18:41 +0000
    Re: question about linker Ike Naar <ike@sdf.org> - 2024-12-06 19:14 +0000
      Re: question about linker Bart <bc@freeuk.com> - 2024-12-06 19:27 +0000
      Re: question about linker scott@slp53.sl.home (Scott Lurndal) - 2024-12-06 22:30 +0000
        Re: question about linker Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-12-06 15:17 -0800
        Re: question about linker Bart <bc@freeuk.com> - 2024-12-07 00:30 +0000
          Re: question about linker Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-12-06 18:01 -0800
    Re: question about linker David Brown <david.brown@hesbynett.no> - 2024-12-07 16:57 +0100
      Re: question about linker Bart <bc@freeuk.com> - 2024-12-07 16:52 +0000
        Re: question about linker David Brown <david.brown@hesbynett.no> - 2024-12-07 18:58 +0100
          Re: question about linker Bart <bc@freeuk.com> - 2024-12-07 19:02 +0000
            Re: question about linker David Brown <david.brown@hesbynett.no> - 2024-12-07 22:00 +0100
              Re: question about linker Bart <bc@freeuk.com> - 2024-12-07 21:18 +0000
                Re: question about linker Ben Bacarisse <ben@bsb.me.uk> - 2024-12-07 23:13 +0000
                Re: question about linker Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-12-07 15:50 -0800
                Re: question about linker Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-12-11 08:52 -0800
                Re: question about linker David Brown <david.brown@hesbynett.no> - 2024-12-08 11:52 +0100
    Re: question about linker antispam@fricas.org (Waldek Hebisch) - 2024-12-08 22:52 +0000
      Re: question about linker Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-12-09 18:35 +0100
      Re: question about linker bart <bc@freeuk.com> - 2024-12-10 12:10 +0000

csiph-web