Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #75691 > unrolled thread
| Started by | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| First post | 2015-11-10 14:20 -0800 |
| Last post | 2015-11-18 01:04 +0000 |
| Articles | 20 on this page of 78 — 16 participants |
Back to article view | Back to comp.lang.c
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
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 12:32 -0800 |
| Message-ID | <22d7dea2-f008-4297-9c6a-45a552fb12f0@googlegroups.com> |
| In reply to | #76007 |
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, just in an incomplete and
shockingly dangerous way:
int foo(char *s, int n, int ferrah())
{
if (*s == ' ') return(foo(s+1, n, ferrah));
else return(ferrah(5.0f,
"boom!",
"what?",
"no type checking?",
"no parameter count checking?",
"dangerous as all get out!",
"don't do it",
"I'm begging you, Tim.",
"There are better ways to code!"));
}
int bas(char *s, int n)
{
if (*s == 0) return(n);
else if (*s != ' ') return(bas(s+1, n));
else return(foo(s, n, bas));
}
Nick's point stands firm. You did declare it twice, and did so in a
wonderful example of how /not/ to write any code. Ever.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 00:15 +0000 |
| Message-ID | <87fv08w22h.fsf@bsb.me.uk> |
| In reply to | #76017 |
"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,
How many times is the integer x declared here:
int foo(int an_int_parameter) { return an_int_parameter + 1; }
int x = 42;
? If your answer is twice, why? If it is once, why does the same
argument not apply to Tim's example?
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 16:34 -0800 |
| Message-ID | <a1bf3c49-5dbd-430c-8b28-0184497e94b7@googlegroups.com> |
| In reply to | #76055 |
On Saturday, November 14, 2015 at 7:15:11 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,
>
> How many times is the integer x declared here:
>
> int foo(int an_int_parameter) { return an_int_parameter + 1; }
>
> int x = 42;
>
> ? If your answer is twice, why? If it is once, why does the same
> argument not apply to Tim's example?
Is the two-line source code you included here your complete example?
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 01:54 +0000 |
| Message-ID | <874mgovxgo.fsf@bsb.me.uk> |
| In reply to | #76060 |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> On Saturday, November 14, 2015 at 7:15:11 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,
>>
>> How many times is the integer x declared here:
>>
>> int foo(int an_int_parameter) { return an_int_parameter + 1; }
>>
>> int x = 42;
>>
>> ? If your answer is twice, why? If it is once, why does the same
>> argument not apply to Tim's example?
>
> Is the two-line source code you included here your complete example?
Yes.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 18:00 -0800 |
| Message-ID | <f8f12796-2e10-4ba3-abfe-cda2ae2c39b5@googlegroups.com> |
| In reply to | #76067 |
On Saturday, November 14, 2015 at 8:54:41 PM UTC-5, Ben Bacarisse wrote:
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>
> > On Saturday, November 14, 2015 at 7:15:11 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,
> >>
> >> How many times is the integer x declared here:
> >>
> >> int foo(int an_int_parameter) { return an_int_parameter + 1; }
> >>
> >> int x = 42;
> >>
> >> ? If your answer is twice, why? If it is once, why does the same
> >> argument not apply to Tim's example?
> >
> > Is the two-line source code you included here your complete example?
>
> Yes.
Ah. I thought it was a trick question.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 02:13 +0000 |
| Message-ID | <87si48ui1d.fsf@bsb.me.uk> |
| In reply to | #76069 |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> On Saturday, November 14, 2015 at 8:54:41 PM UTC-5, Ben Bacarisse wrote:
>> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>>
>> > On Saturday, November 14, 2015 at 7:15:11 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,
>> >>
>> >> How many times is the integer x declared here:
>> >>
>> >> int foo(int an_int_parameter) { return an_int_parameter + 1; }
>> >>
>> >> int x = 42;
>> >>
>> >> ? If your answer is twice, why? If it is once, why does the same
>> >> argument not apply to Tim's example?
>> >
>> > Is the two-line source code you included here your complete example?
>>
>> Yes.
>
> Ah. I thought it was a trick question.
No. In Tim's example I see two functions, each declared once. You
appeared to be referring to the function parameter as declaring one or
other function a second time. I constructed an example with an int
declaration and a function with an int parameter to see if you
considered the int parameter to be a second declaration of something
already declared.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 18:26 -0800 |
| Message-ID | <e6d5938b-5497-4c55-a2de-82d532b442c1@googlegroups.com> |
| In reply to | #76071 |
On Saturday, November 14, 2015 at 9:13:13 PM UTC-5, Ben Bacarisse wrote:
> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
>
> > On Saturday, November 14, 2015 at 8:54:41 PM UTC-5, Ben Bacarisse wrote:
> >> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes:
> >>
> >> > On Saturday, November 14, 2015 at 7:15:11 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,
> >> >>
> >> >> How many times is the integer x declared here:
> >> >>
> >> >> int foo(int an_int_parameter) { return an_int_parameter + 1; }
> >> >>
> >> >> int x = 42;
> >> >>
> >> >> ? If your answer is twice, why? If it is once, why does the same
> >> >> argument not apply to Tim's example?
> >> >
> >> > Is the two-line source code you included here your complete example?
> >>
> >> Yes.
> >
> > Ah. I thought it was a trick question.
>
> No. In Tim's example I see two functions, each declared once. You
> appeared to be referring to the function parameter as declaring one or
> other function a second time. I constructed an example with an int
> declaration and a function with an int parameter to see if you
> considered the int parameter to be a second declaration of something
> already declared.
Yes. I understood that. That's why I thought it was a trick question.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 02:34 +0000 |
| Message-ID | <87h9kouh2b.fsf@bsb.me.uk> |
| In reply to | #76072 |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: <snip> > Yes. I understood that. That's why I thought it was a trick > question. I was probably being too oblique. I'll go back and ask a more direct question. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2015-11-15 11:11 +0000 |
| Message-ID | <n29p43$r44$1@dont-email.me> |
| In reply to | #76071 |
On 15/11/2015 02:13, 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,
>>>>>
>>>>> How many times is the integer x declared here:
>>>>>
>>>>> int foo(int an_int_parameter) { return an_int_parameter + 1; }
>>>>>
>>>>> int x = 42;
>>>>>
>>>>> ? If your answer is twice, why? If it is once, why does the same
>>>>> argument not apply to Tim's example?
>> Ah. I thought it was a trick question.
>
> No. In Tim's example I see two functions, each declared once.
The functions are defined once each. There is also a function pointer
declared once, as a device used to be able to refer to a function not
visible in the source until later.
This is a roundabout way of getting around the challenge and is not
completely satisfactory:
* It's harder to follow the code
* The mutual call isn't direct but via a pointer; it's less efficient
* It's possible that function pointer is to some other unrelated function.
* If you wanted to reverse the relative order in the source of foo() and
bas(), then you have to rewrite the functions.
Better is something like this (I don't know if it does the same; as I
said it was harder to read):
int
foo( char *s, int n){
if( *s == ' ' ) return foo( s+1, n);
return bas( s, n+1 );
}
int
bas( char *s, int n ){
if( *s == 0 ) return n;
if( *s != ' ' ) return bas( s+1, n );
return foo( s, n);
}
but this requires at least one forward declaration (although gcc only
gave me a warning). Two forward declarations mean the functions can be
in any order.
The challenge is to be able to write direct code like this, without any
of the complications I listed, without any forward declarations.
--
Bartc
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 02:36 +0000 |
| Message-ID | <87bnawugyi.fsf@bsb.me.uk> |
| In reply to | #76017 |
"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.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 19:25 -0800 |
| Message-ID | <7c2d6623-b4bb-47e5-9482-16f39532dbe1@googlegroups.com> |
| In reply to | #76074 |
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.
You say, you "need [me] to say exactly..." Well, what if I were to
refuse that need? What would you do then, Ben?
I mean, if it's truly a "need" of some kind, as you indicate, would it
cause a type of physical or mental breakdown resulting in injury, or
worse, were I to not answer?
And if so, why would you place yourself in such a precarious position,
one which is entirely contingent upon my response? And if not, then
why would you use wording stating you have a "need" when you really
don't? Surely you meant to say "want" and not "need," right? At
least I hope so because ... whew! What a way to be otherwise, yes?
-----
Okay ... bottom line ... I'm content to answer your inquiry, Ben, but
first I need to know how much pressure there is upon my reply? Is it
more than 4 units?
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 19:37 -0800 |
| Message-ID | <aeff3039-9d60-4e0d-9807-73d2287146d4@googlegroups.com> |
| In reply to | #76074 |
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 wife said I was being "Rick funny" in my previous post, and that
people might not realize it was my sense of humor. So, if that's
the case, I apologize.
Here's my real answer:
"Yes. Pizza is my favorite food."
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-14 20:11 -0800 |
| Message-ID | <edc97cb1-60df-45a6-b81e-9e1794244119@googlegroups.com> |
| In reply to | #76074 |
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. One is a function parameter declaration of a
function. The other is a function body declaration.
In order for that code to work, three function declarations are
required (admittedly one of them is a partial and dangerous
declaration). Still, it could not be done without the three.
It could not be done like this:
int
foo( char *s, int n ){
if( *s == ' ' ) return foo( s+1, n );
return bas( s, n+1 );
}
int
bas( char *s, int n ){
if( *s == 0 ) return n;
if( *s != ' ' ) return bas( s+1, n );
return foo( s, n );
}
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 10:36 +0000 |
| Message-ID | <876113v9b8.fsf@bsb.me.uk> |
| In reply to | #76078 |
"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. But it was not kind to ask. I should simply have corrected what
you said and left it at that.
> 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. There are only two functions in total, and two function
declarations in total. No function is declared twice.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-15 06:16 -0800 |
| Message-ID | <97e66a45-03e0-40ea-96fc-0cbeef3b1319@googlegroups.com> |
| In reply to | #76084 |
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.
> But it was not kind to ask. I should simply have corrected what
> you said and left it at that.
That's why Jesus gave us forgiveness. He forgives us. We forgive
others.
I forgive you, Ben. And I pray for you as the Lord brings you to
my remembrance. Thus far the pattern of me remembering you is in
your replies to me, and then in your absence of replies to me. It
seems you're "on my mind" in that regard ... it's like the Lord has
purposed within me an ongoing series of prayers for you.
> > 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?
> 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: three functions are referenced. Two
function declarations, one function declaration within the parameter
list of one of those two, 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.
Best regards,
Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2015-11-15 14:44 +0000 |
| Message-ID | <n2a5kh$fr8$1@dont-email.me> |
| In reply to | #76093 |
On 15/11/2015 14:16, Rick C. Hodgin wrote: > On Sunday, November 15, 2015 at 5:36:27 AM UTC-5, Ben Bacarisse wrote: >> 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. That's not true. You can declare a function pointer without it being initialised or tied to any actual functions. Obviously there have to be some functions or you wouldn't be able to write any code at all. In Tim's example, you could have said that the function pointer was a kind of incomplete forward declaration; one that was not filled in by the compiler, but by the code at runtime. Then the empty pointer is filled in by giving more details of the function in question. Tim also avoided having to give a proper function signature to the pointer, relying on implicit declarations, as otherwise it be effectively declaring even more of bas() in advance. Together with my other comments, it's not an ideal solution, however it sort of works by having two mutually recursive functions with only two conventional declarations. But in this case, it would be simpler to just have the forward declarations! -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | "Rick C. Hodgin" <rick.c.hodgin@gmail.com> |
|---|---|
| Date | 2015-11-15 09:41 -0800 |
| Message-ID | <4769f4ec-99fc-4f8d-aa9f-124178189371@googlegroups.com> |
| In reply to | #76094 |
On Sunday, November 15, 2015 at 9:45:00 AM UTC-5, Bart wrote: > On 15/11/2015 14:16, Rick C. Hodgin wrote: > > On Sunday, November 15, 2015 at 5:36:27 AM UTC-5, Ben Bacarisse wrote: > > >> 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. > > That's not true. You can declare a function pointer without it being > initialised or tied to any actual functions. You can do that in terms of general variable creation, but not in terms of a function parameter declaration. In the case of function parameter declaration, be it in the prototype or the function body, the declaration is always there, and always provides the declaration, and, provided the function is called, it is also always defined in usage (as by the passed value). Best regards, Rick C. Hodgin
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 18:26 +0000 |
| Message-ID | <87d1vbt8y7.fsf@bsb.me.uk> |
| In reply to | #76096 |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: > On Sunday, November 15, 2015 at 9:45:00 AM UTC-5, Bart wrote: >> On 15/11/2015 14:16, Rick C. Hodgin wrote: >> > On Sunday, November 15, 2015 at 5:36:27 AM UTC-5, Ben Bacarisse wrote: >> >> >> 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. >> >> That's not true. You can declare a function pointer without it being >> initialised or tied to any actual functions. > > You can do that in terms of general variable creation, but not in > terms of a function parameter declaration. C does not have function parameters. The example had a pointer parameter. > In the case of function > parameter declaration, be it in the prototype or the function body, > the declaration is always there, and always provides the declaration, > and, provided the function is called, it is also always defined in > usage (as by the passed value). Nonsense. In the case of an object, be it in the prototype or the function body, the declaration is always there, and always provides the declaration, and, provided the function is called, it is also always defined in usage (as by the passed value). You are trying to invent a distinction between function pointers and other kinds of object that is simply not there. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | BartC <bc@freeuk.com> |
|---|---|
| Date | 2015-11-15 18:42 +0000 |
| Message-ID | <n2aji7$a3j$1@dont-email.me> |
| In reply to | #76099 |
On 15/11/2015 18:26, Ben Bacarisse wrote: > "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: > >> You can do that in terms of general variable creation, but not in >> terms of a function parameter declaration. > > C does not have function parameters. The example had a pointer > parameter. > >> In the case of function >> parameter declaration, be it in the prototype or the function body, >> the declaration is always there, and always provides the declaration, >> and, provided the function is called, it is also always defined in >> usage (as by the passed value). > > Nonsense. In the case of an object, be it in the prototype or the > function body, the declaration is always there, and always provides the > declaration, and, provided the function is called, it is also always > defined in usage (as by the passed value). You are trying to invent a > distinction between function pointers and other kinds of object that is > simply not there. There is a subtle difference. A properly written declaration for a function pointer would need to specify the function signature: the parameter types and return type. But the function signature is already most of the information that would be in a forward declaration and that is necessary for the function to be correctly called. All that's missing is the name of the function. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-15 18:53 +0000 |
| Message-ID | <874mgnt7qk.fsf@bsb.me.uk> |
| In reply to | #76101 |
BartC <bc@freeuk.com> writes: > On 15/11/2015 18:26, Ben Bacarisse wrote: >> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: >> > >>> You can do that in terms of general variable creation, but not in >>> terms of a function parameter declaration. >> >> C does not have function parameters. The example had a pointer >> parameter. >> >>> In the case of function >>> parameter declaration, be it in the prototype or the function body, >>> the declaration is always there, and always provides the declaration, >>> and, provided the function is called, it is also always defined in >>> usage (as by the passed value). >> >> Nonsense. In the case of an object, be it in the prototype or the >> function body, the declaration is always there, and always provides the >> declaration, and, provided the function is called, it is also always >> defined in usage (as by the passed value). You are trying to invent a >> distinction between function pointers and other kinds of object that is >> simply not there. > > There is a subtle difference. A properly written declaration for a > function pointer would need to specify the function signature: the > parameter types and return type. That's not subtle. Function pointer declarations are different to other declarations in significant ways. They are just not different in the way that Rick would like then to be. > But the function signature is already most of the information that > would be in a forward declaration and that is necessary for the > function to be correctly called. All that's missing is the name of the > function. A pointer to int has even more -- it contains *all* the information for the int to be used. All that's missing is the int it points to. -- Ben.
[toc] | [prev] | [next] | [standalone]
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web