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


Groups > comp.lang.c > #70019

Re: disadvantages of using old parameter syntax?

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: disadvantages of using old parameter syntax?
Date 2015-09-09 02:47 +0100
Organization A noiseless patient Spider
Message-ID <87si6ol5xk.fsf@bsb.me.uk> (permalink)
References <msc3ru$d6a$1@speranza.aioe.org> <msc8l0$rjd$1@dont-email.me> <7e4a07d7-c3b1-4e85-b4c6-baff554aa73c@googlegroups.com> <87y4ggl88u.fsf@bsb.me.uk> <826a3edc-d200-43c5-a94f-f6fd00d6b000@googlegroups.com>

Show all headers | View raw


"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:

> On Tuesday, September 8, 2015 at 8:57:47 PM UTC-4, Ben Bacarisse wrote:
>> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>> 
>> > On Friday, September 4, 2015 at 10:10:33 AM UTC-4, Eric Sosman wrote:
>> >> On 9/4/2015 8:46 AM, Anonymous Shadow wrote:
>> >> > Are there any important differences I should know about when writing
>> >> > code like this:
>> >> >
>> >> > int
>> >> > main(argc, argv)
>> >> >      int argc;
>> >> >      char* argv[];
>> >> > {
>> >> >      do_stuff(argc, argv);
>> >> >      return EXIT_SUCCESS;
>> >> > }
>> >> >
>> >> > as opposed to this:
>> >> >
>> >> > int
>> >> > main(int argc, char *argv[])
>> >> > {
>> >> >      do_stuff(argc, argv);
>> >> >      return EXIT_SUCCESS;
>> >> > }
>> >> 
>> >>      Use the newer form, not the older.
>> >> 
>> >>      The older form does not provide a prototype to "advertise" the
>> >> parameters to the rest of the program.  When the compiler sees a call
>> >> to a non-prototyped function, it will not necessarily check the number
>> >> and types of the argument expressions for agreement with the parameters.
>> >
>> > This seems like something that could be changed about the compiler,
>> > allowing the old syntax form to operate like the new one.
>> 
>> In many cases it can't because the old syntax is simply lacking the
>> information required.
>
> Is there a form which is unlike the example above, because that one
> seems to have all the information in the new form, it's just arranged
> differently?  I assume there is, hence your comment here. :-)

I suspect I'm wading into another zone where you don't know which terms
are technical ones and which just have vague meanings.  The two forms
shown convey different information, though the differences are subtle
and, as I've said, simply not worth resurrecting.  The most striking
thing about old C are function declarations that are not definitions.
When the compiler sees a call to

   f(2, 3.5, 1.2);

all it has probably seen is a declaration which is not a prototype

   extern f();

It simply lacks the information to say of the call is correct or not.
More subtly, it can't convert any of the arguments.

In some other file we find the definition:

  int f(a, b, c)
  double a, b, c;
  { ... }

and things look bad.  A value of completely the wrong type (and
probably size) is being passed.  The compiler can't either diagnose the
error help correct it.  With modern C, the function would be declared
with a prototype

  int f(double a, double b, double c);

and the first argument, "3", would be converted to a double.  And if the
number of arguments was wrong, you'll get a message.  A K&R C compiler
must accept both the call above and one like f(1).  It has no idea
which is correct (and both might be).

>> In the more common case of using a function with only a
>> declaration ins scope, there is nothing to go on:
>> 
>>   int printf();
>>   double sin();
>
> Yes, I would think that should've either been done away with, or
> equated to this formal declaration:
>
>     int printf(void);
>     double sin(void);
>
>> > In addition,
>> > what's to prevent the old syntax from being prototyped in a .h file?
>> 
>> I don't know what that means.  You can't give prototypes for old-syntax
>> function declarations, if that's what you mean, because you'll change
>> the meaning of the code in some cases.
>
> Well ... I don't see how that would be possible.

I've written enough already about what is an obsolete syntax.  Can you
just take my word for it?  There are old C functions for which it is not
possible to write a modern C prototype without altering the meaning.

> I would think the
> C compiler would find the second instance, which did not have its
> parameters specified by types, and use the prototype, or, if they
> were specified by types and they varied, then it would generate an
> error that something was wrong.

I've no idea what this is about.

>> > Do modern C compilers ignore forward declarations when they encounter
>> > the old style syntax?
>> 
>> They have to handle it as old compilers did.  It's important for old
>> code that the semantics remain the same.
>> 
>>   void f(float f) { ... }
>>   void f(f) float f; { ... }
>> 
>> do not mean quite the same thing.  The declaration is not ignored but
>> must be take to mean what K&R intended.
>
> That's what my comment meant that compilers could be changed to have
> them mean the same thing.

Do you mean you'd be happy to have a compiler that just changed what
previously correct existing programs mean?  C has wisely not done that.
The old form still means what it meant and the new form means what C90
(and later) says it means.

<snip>
-- 
Ben.

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


Thread

disadvantages of using old parameter syntax? Anonymous Shadow <rocket.penguin@riseup.net> - 2015-09-04 20:46 +0800
  Re: disadvantages of using old parameter syntax? Anonymous Shadow <rocket.penguin@riseup.net> - 2015-09-04 20:49 +0800
    Re: disadvantages of using old parameter syntax? raltbos@xs4all.nl (Richard Bos) - 2015-09-04 16:19 +0000
  Re: disadvantages of using old parameter syntax? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-04 10:10 -0400
    Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 17:07 -0700
      Re: disadvantages of using old parameter syntax? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-09 01:57 +0100
        Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 18:09 -0700
          Re: disadvantages of using old parameter syntax? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-09 02:47 +0100
            Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 19:34 -0700
              Re: disadvantages of using old parameter syntax? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-09-09 12:07 +0100
          Re: disadvantages of using old parameter syntax? David Brown <david.brown@hesbynett.no> - 2015-09-09 13:18 +0200
  Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-04 07:23 -0700
    Re: disadvantages of using old parameter syntax? mark.bluemel@gmail.com - 2015-09-04 07:45 -0700
    Re: disadvantages of using old parameter syntax? David Brown <david.brown@hesbynett.no> - 2015-09-05 14:59 +0200
      Re: disadvantages of using old parameter syntax? Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-07 13:26 -0700
        Re: disadvantages of using old parameter syntax? David Brown <david.brown@hesbynett.no> - 2015-09-08 08:51 +0200
      Re: (Not) discussing C-like toy languages Noob <root@127.0.0.1> - 2015-09-08 13:35 +0200
        Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-08 13:59 +0200
          Re: (Not) discussing C-like toy languages gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-08 12:35 +0000
            Re: (Not) discussing C-like toy languages Noob <root@127.0.0.1> - 2015-09-08 17:55 +0200
              Re: (Not) discussing C-like toy languages James Kuyper <jameskuyper@verizon.net> - 2015-09-08 13:11 -0400
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 10:19 -0700
                Re: (Not) discussing C-like toy languages Noob <root@127.0.0.1> - 2015-09-08 21:31 +0200
                Re: (Not) discussing C-like toy languages Richard Heathfield <rjh@cpax.org.uk> - 2015-09-08 20:33 +0100
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-08 22:56 +0200
                Re: (Not) discussing C-like toy languages raltbos@xs4all.nl (Richard Bos) - 2015-09-20 19:31 +0000
                Re: (Not) discussing C-like toy languages James Kuyper <jameskuyper@verizon.net> - 2015-09-20 16:09 -0400
                Re: (Not) discussing C-like toy languages Morris Dovey <mrdovey@iedu.com> - 2015-09-21 18:51 -0500
                Re: (Not) discussing C-like toy languages Richard Heathfield <rjh@cpax.org.uk> - 2015-09-20 21:27 +0100
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-08 22:52 +0200
                Re: (Not) discussing C-like toy languages Richard Heathfield <rjh@cpax.org.uk> - 2015-09-08 21:59 +0100
                Re: (Not) discussing C-like toy languages raltbos@xs4all.nl (Richard Bos) - 2015-09-20 19:31 +0000
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-20 13:54 -0700
            Re: (Not) discussing C-like toy languages Gareth Owen <gwowen@gmail.com> - 2015-09-08 21:28 +0100
        Re: (Not) discussing C-like toy languages James Kuyper <jameskuyper@verizon.net> - 2015-09-08 10:56 -0400
          Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-08 08:33 -0700
            Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-08 09:12 -0700
              Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 09:18 -0700
                Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-08 10:15 -0700
          Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 08:38 -0700
          Re: (Not) discussing C-like toy languages luser droog <luser.droog@gmail.com> - 2015-09-08 16:50 -0700
            Re: (Not) discussing C-like toy languages James Kuyper <jameskuyper@verizon.net> - 2015-09-08 21:24 -0400
              Re: (Not) discussing C-like toy languages luser droog <luser.droog@gmail.com> - 2015-09-11 08:45 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-11 08:54 -0700
                Re: (Not) discussing C-like toy languages luser droog <luser.droog@gmail.com> - 2015-09-11 21:22 -0700
                Re: (Not) discussing C-like toy languages Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-13 06:42 +0000
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-12 23:54 -0700
                Re: (Not) discussing C-like toy languages Les Cargill <lcargill99@comcast.com> - 2015-09-13 10:41 -0500
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-13 09:52 -0700
                Re: (Not) discussing C-like toy languages Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-13 20:27 +0000
                Re: (Not) discussing C-like toy languages Les Cargill <lcargill99@comcast.com> - 2015-09-14 21:32 -0500
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-13 09:55 -0700
                Re: (Not) discussing C-like toy languages Ian Collins <ian-news@hotmail.com> - 2015-09-14 09:07 +1200
                Re: (Not) discussing C-like toy languages "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-09-13 14:23 -0700
                Re: (Not) discussing C-like toy languages Ian Collins <ian-news@hotmail.com> - 2015-09-14 09:31 +1200
                Re: (Not) discussing C-like toy languages "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-09-13 14:33 -0700
                Re: (Not) discussing C-like toy languages Ian Collins <ian-news@hotmail.com> - 2015-09-14 09:40 +1200
                Re: (Not) discussing C-like toy languages "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-09-13 15:05 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 00:10 +0200
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-13 17:16 -0700
                Re: (Not) discussing C-like toy languages Les Cargill <lcargill99@comcast.com> - 2015-09-14 21:36 -0500
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-13 14:29 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-13 23:47 +0200
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-13 17:55 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 10:20 +0200
                Re: (Not) discussing C-like toy languages Richard Heathfield <rjh@cpax.org.uk> - 2015-09-14 11:01 +0100
                Re: (Not) discussing C-like toy languages Ian Collins <ian-news@hotmail.com> - 2015-09-14 22:07 +1200
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 12:41 +0200
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-14 03:47 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 04:05 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 04:20 -0700
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-14 05:51 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 06:06 -0700
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-14 06:26 -0700
                Re: (Not) discussing C-like toy languages gazelle@shell.xmission.com (Kenny McCormack) - 2015-09-14 13:43 +0000
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-14 07:26 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 06:47 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 03:31 -0700
                Re: (Not) discussing C-like toy languages James Kuyper <jameskuyper@verizon.net> - 2015-09-14 06:40 -0400
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 14:27 +0200
                Re: (Not) discussing C-like toy languages Richard Heathfield <rjh@cpax.org.uk> - 2015-09-14 13:39 +0100
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 05:55 -0700
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 05:50 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 15:58 +0200
                Re: (Not) discussing C-like toy languages "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 07:37 -0700
                Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-14 07:43 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 17:21 +0200
                Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-14 08:53 -0700
                Re: (Not) discussing C-like toy languages David Brown <david.brown@hesbynett.no> - 2015-09-14 18:23 +0200
                Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-14 10:57 -0700
                Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-17 17:43 -0700
                Re: (Not) discussing C-like toy languages raltbos@xs4all.nl (Richard Bos) - 2015-09-20 20:50 +0000
                Re: (Not) discussing C-like toy languages raltbos@xs4all.nl (Richard Bos) - 2015-09-20 20:48 +0000
                Re: (Not) discussing C-like toy languages Keith Thompson <kst-u@mib.org> - 2015-09-14 07:58 -0700
                Re: (Not) discussing C-like toy languages Les Cargill <lcargill99@comcast.com> - 2015-09-14 21:35 -0500
            Re: (Not) discussing C-like toy languages Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-09-08 23:56 -0700
        Re: (Not) discussing C-like toy languages fir <profesor.fir@gmail.com> - 2015-09-08 08:07 -0700
    Re: disadvantages of using old parameter syntax? luser droog <luser.droog@gmail.com> - 2015-09-08 17:40 -0700
      Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-08 17:59 -0700
  Re: disadvantages of using old parameter syntax? James Kuyper <jameskuyper@verizon.net> - 2015-09-04 10:48 -0400
  Re: disadvantages of using old parameter syntax? Paul N <gw7rib@aol.com> - 2015-09-07 12:48 -0700
  Re: disadvantages of using old parameter syntax? Anonymous Shadow <rocket.penguin@riseup.net> - 2015-09-12 15:35 +0800
    Re: disadvantages of using old parameter syntax? Keith Thompson <kst-u@mib.org> - 2015-09-12 14:25 -0700
      Re: disadvantages of using old parameter syntax? supercat@casperkitty.com - 2015-09-12 14:53 -0700
        Re: disadvantages of using old parameter syntax? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-12 18:21 -0400
  Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-14 11:41 -0700
    Re: disadvantages of using old parameter syntax? Rosario19 <Ros@invalid.invalid> - 2015-09-16 09:02 +0200
      Re: disadvantages of using old parameter syntax? "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-09-16 01:12 -0700

csiph-web