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


Groups > comp.lang.c > #148894

Re: K&R function definition with typedef parameter names

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c
Subject Re: K&R function definition with typedef parameter names
Date 2020-01-10 10:22 +0100
Organization A noiseless patient Spider
Message-ID <qv9fo5$j60$1@dont-email.me> (permalink)
References (1 earlier) <qurt8i$uqk$1@news.albasani.net> <qv7d3s$1nnr$1@gioia.aioe.org> <qv7gfc$oir$1@news.albasani.net> <3eba021e-5533-4582-b2db-040965839eeb@googlegroups.com> <a9bd7ff2-4f04-4b8c-9d7f-c194b32d76a5@googlegroups.com>

Show all headers | View raw


On 09/01/2020 19:49, Thiago Adams wrote:
> On Thursday, January 9, 2020 at 1:20:15 PM UTC-3, James Kuyper wrote:
>> As of the latest version of the C standard,  K&R style function definitions are still permitted. A fully conforming implementation of C is therefore required to accept such code and to translate it correctly. It's free to also issue a warning, which I would strongly recommend, but it is not permitted to reject code for that reason. 
>> Given that this syntax is still permitted, I think it's likely that there's at least a few idiots somewhere still writing new code using that syntax. The committee would have at least deprecated the syntax a long time ago if they didn't think there were a fair number of people who still need it to be supported.
> 
> I never used this syntax.
> However, I can see where it can be useful.
> 
> If you are writing code from other language, for instance, 
> you have your own language that the output is C,then
> this feature and others like ignore function declarations,
> is useful. In this case C is more like an "portable assembly"
> and warnings are not necessary considering that the other
> language is already making checks.
> 

If you are compiling from another language, using C as an intermediary
language, then there are basically two paths to take.  One is that /you/
choose the C compiler and options - in which case you can disable any
warnings, use compiler extensions and implementation-dependent features,
etc.  The other is that the user chooses the C compiler, and then you
want to generate as clean and portable code as you can, that aims to be
warning-free for any reasonable (for some definition of "reasonable")
choice of compiler, flags and warnings that the user picks.

Either way, but perhaps especially for the "language writer chooses the
compiler" way, you want to end up with the most efficient results
practical.  You generate code that gives the compiler the most knowledge
and the best opportunities for optimisation.  Skipping function
declarations, and relying on non-prototype function calls, is a sure way
to generate pointlessly poorer code.

You won't necessarily structure you code in the way a human programmer
might.  In normal C programming, it is common to put the prototype
declarations of external linkage functions in a header, which is
included by C units that use the functions and also by the one that
defines it.  In generated C code, you might skip that and directly add
function declarations of called functions at their point of use in the C
files.  That would be a maintenance nightmare for manually written code,
but absolutely fine for generated code.  There would be advantages in
avoiding (or minimising) the generation of header files - there would be
no advantage in skipping function prototypes.

And I am completely at a loss to see how K&R style function definitions
ever offer any kind of advantage over modern C function definitions with
full prototypes.  Maybe I have missed something that you are thinking
about, and you can elaborate.

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