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


Groups > comp.lang.c > #76095

Re: Forward declarations

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Forward declarations
Date 2015-11-15 14:54 +0000
Organization A noiseless patient Spider
Message-ID <87io53tis5.fsf@bsb.me.uk> (permalink)
References (6 earlier) <22d7dea2-f008-4297-9c6a-45a552fb12f0@googlegroups.com> <87bnawugyi.fsf@bsb.me.uk> <edc97cb1-60df-45a6-b81e-9e1794244119@googlegroups.com> <876113v9b8.fsf@bsb.me.uk> <97e66a45-03e0-40ea-96fc-0cbeef3b1319@googlegroups.com>

Show all headers | View raw


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

> On Sunday, November 15, 2015 at 5:36:27 AM UTC-5, Ben Bacarisse wrote:
>> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>> 
>> > On Saturday, November 14, 2015 at 9:36:29 PM UTC-5, Ben Bacarisse wrote:
>> >> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>> >> 
>> >> > On Saturday, November 14, 2015 at 2:50:19 PM UTC-5, Tim Rentsch wrote:
>> >> >> Nick Bowler <nbowler@draconx.ca> writes:
>> >> >> 
>> >> >> > It is currently impossible in C to write mutually recursive
>> >> >> > functions without declaring at least one of the functions twice.
>> >> >> 
>> >> >> I wouldn't bet money on that if I were you -
>> >> >> 
>> >> >>     int
>> >> >>01:  foo( char *s, int n, int ferrah() ){
>> >> >>         if(  *s == ' '  )  return  foo( s+1, n, ferrah );
>> >> >>         return  ferrah( s, n+1 );
>> >> >>     }
>> >> >> 
>> >> >>02:  int
>> >> >>     bas( char *s, int n ){
>> >> >>         if(  *s == 0  )  return  n;
>> >> >>         if(  *s != ' '  )  return  bas( s+1, n );
>> >> >>         return  foo( s, n, bas );
>> >> >>     }
>> >> >
>> >> > Technically, you did declared it twice,
>> >> 
>> >> Being more direct this time...  What function is declared twice in that
>> >> code?  Where are the two declarations?  You marked lines but the lines
>> >> are for declarations of two different functions so I need you to say
>> >> exactly where you see the second declaration.
>> >
>> > My serious answer:  I showed the 01: and 02: lines.  They contain
>> > the definitions.
>> 
>> That does not answer the first question about which function is declared
>> twice.
>
> It does.  A function pointer cannot be declared without declaring the
> existence of /A/ function.  In this case the function declaration was
> partial, and dangerous, but it was a function declaration indicating
> that a function would be referenced through ferrah.

That's not a function declaration -- It's the declaration of a pointer.
But even if it were of function type, it's a parameter -- a new "thing"
(instantiated on every call) not a second declaration of something
else.  (I have to say "thing", because C does not have function objects
or function values so there is no terminology to talk about functions as
parameters.)

That, by the way, was the point of my example with an int.  Declaring an
int parameter does mean the existing int has been declared twice.  You
only wanted to joke about that, but there was a point to it.

<snip>
>> > One is a function parameter declaration of a
>> > function.  The other is a function body declaration.
>> 
>> No, the code contains contains two function declarations, two char
>> pointer declarations, an int declaration and a function pointer
>> declaration.
>
> How does one declare a function pointer declaration without declaring
> a function, or casting it into the role of a function, albeit in this
> instance in a more limited scope than a true function declaration?

No one in claiming that the function whose address will be passed is not
declared.  You asserted that some function is declared *twice* -- that's
the error.  There are only two function declarations and two functions,
so there is one declaration each.

>> There are only two functions in total, and two function
>> declarations in total.  No function is declared twice.
>
> I'm sure you see my point:

Yes, of course.  How could I know it's wrong if I did not see what you
are saying?

> [...] three functions are referenced. Two
> function declarations, one function declaration within the parameter
> list of one of those two,

No, there is no function declaration in the parameter list.  Perhaps you
don't know that the declaration is of a pointer type?  But even if C
actually had function parameters, you'd still be wrong -- a function
parameter declares something new; it is never a second declaration of
something already declared.

> indicating the existence of another
> function, one which MAY be one of the original two, but doesn't
> have to be, but in Tim's case is.

You didn't say "there's a pointer to an already declared function" you
said (or implied by not accepting the counter-example) that at least one
function had to be declared twice.

In summary:

1. The parameter is not a function.  The declaration is of "pointer to
function" type.  A declaration of something of type T *, can never be a
declaration of something of type T.

2. A declared parameter is not a second declaration of anything, no
matter what value is eventually passed to the function.  A parameter
declaration is of a new object with automatic lifetime and never a
second declaration of something else.

-- 
Ben.

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


Thread

Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-10 14:20 -0800
  Re: Forward declarations jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-10 23:38 +0100
    Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-10 15:00 -0800
      Re: Forward declarations Ian Collins <ian-news@hotmail.com> - 2015-11-11 12:24 +1300
        Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-10 15:53 -0800
          Re: Forward declarations gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-11 00:01 +0000
          Re: Forward declarations Ian Collins <ian-news@hotmail.com> - 2015-11-11 13:46 +1300
            Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-10 21:05 -0800
    Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-11 00:21 +0000
  Re: Forward declarations Lőrinczy Zsigmond <zsiga@nospam.for.me> - 2015-11-11 10:16 +0100
    Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-11 07:19 -0800
  Re: Forward declarations David Brown <david.brown@hesbynett.no> - 2015-11-11 15:40 +0100
    Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-11 07:21 -0800
      Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-11 07:23 -0800
      Re: Forward declarations David Brown <david.brown@hesbynett.no> - 2015-11-11 16:29 +0100
        Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-11 07:31 -0800
        Re: Forward declarations Nick Bowler <nbowler@draconx.ca> - 2015-11-13 18:20 +0000
          Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-13 10:39 -0800
            Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-13 19:40 +0000
          Re: Forward declarations Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-14 11:42 -0800
            Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 12:32 -0800
              Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 00:15 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 16:34 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 01:54 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 18:00 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 02:13 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 18:26 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 02:34 +0000
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-15 11:11 +0000
              Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 02:36 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 19:25 -0800
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 19:37 -0800
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-14 20:11 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 10:36 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 06:16 -0800
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-15 14:44 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 09:41 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 18:26 +0000
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-15 18:42 +0000
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 18:53 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 12:58 -0800
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 12:49 -0800
                Re: Forward declarations Ian Collins <ian-news@hotmail.com> - 2015-11-16 10:01 +1300
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-15 14:54 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 09:53 -0800
                Re: Forward declarations Keith Thompson <kst-u@mib.org> - 2015-11-15 10:36 -0800
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 12:56 -0800
                Re: Forward declarations Ian Collins <ian-news@hotmail.com> - 2015-11-16 10:04 +1300
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 13:11 -0800
                Re: Forward declarations Ian Collins <ian-news@hotmail.com> - 2015-11-16 10:25 +1300
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 13:37 -0800
              Re: Forward declarations Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-15 13:13 -0800
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 13:16 -0800
                Re: Forward declarations David Brown <david.brown@hesbynett.no> - 2015-11-16 00:23 +0100
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 16:20 -0800
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-16 00:47 +0000
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-16 01:28 +0000
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-16 01:57 +0000
                Re: Forward declarations Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-15 21:15 -0500
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-16 11:05 +0000
                Re: Forward declarations Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-16 10:18 -0500
                Re: Forward declarations Richard Heathfield <rjh@cpax.org.uk> - 2015-11-16 06:44 +0000
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-16 11:26 +0000
                Re: Forward declarations David Brown <david.brown@hesbynett.no> - 2015-11-16 12:43 +0100
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-16 12:20 +0000
                Re: Forward declarations David Brown <david.brown@hesbynett.no> - 2015-11-16 14:38 +0100
                Re: Forward declarations Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-16 13:26 +0000
                Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-16 13:53 +0000
                Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-15 18:12 -0800
      Re: Forward declarations pa@see.signature.invalid (Pierre Asselin) - 2015-11-12 01:54 +0000
        Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-12 02:08 -0800
    Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-12 09:58 +0000
  Re: Forward declarations John Bode <jfbode1029@gmail.com> - 2015-11-17 14:46 -0800
    Re: Forward declarations "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-11-17 14:59 -0800
    Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-17 23:35 +0000
      Re: Forward declarations BartC <bc@freeuk.com> - 2015-11-17 23:40 +0000
        Re: Forward declarations Keith Thompson <kst-u@mib.org> - 2015-11-17 19:48 -0800
      Re: Forward declarations glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-11-18 01:04 +0000

csiph-web