Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #108089
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: correct way to create dynamically function pointers |
| Date | 2017-04-12 16:36 -0700 |
| Organization | None to speak of |
| Message-ID | <lny3v5urju.fsf@kst-u.example.com> (permalink) |
| References | <b6cbce81-b326-4c26-9079-23e083b2de56@googlegroups.com> <ockk7b$dkn$1@dont-email.me> <GPwHA.1005972$Pm3.812399@fx42.am4> <ocm8ga$m8c$1@dont-email.me> |
Richard Heathfield <rjh@cpax.org.uk> writes:
> On 12/04/17 22:17, Spiros Bousbouras wrote:
>> On Wed, 12 Apr 2017 08:19:00 +0100
>> Richard Heathfield <rjh@cpax.org.uk> wrote:
[...]
>>> printf("p[0](4, 6) = %d\n",(*p[0])(4, 6));
>>
>> Or more simply
>> printf("p[0](4, 6) = %d\n",p[0](4, 6));
>
> I disagree that it's necessarily simpler. It's /shorter/, yes.
In any case, it would be nice for the expression in the format string to
match the function call.
> But (*p[0]) tells us something useful - i.e. it reminds us that p[0] is
> a pointer, not a function. Now, okay, I realise that p[0] can't be the
> name of a function! Nevertheless, in the general case I prefer to use
> parentheses (*p)() rather than p() when a function pointer is being
> used, as a little reminder that there's no point in going looking for a
> function p.
I agree that it's a useful reminder. On the other hand, the prefix to a
function call is *always* a expression of pointer-to-function type, so
if one were being deliberately perverse, one could cause great confusion
by inverting the convention:
void func(void) {
/* ... */
}
void (*funcptr)(void) = func;
int main(void) {
(*func)();
funcptr();
}
Not that I'd ever doing such a thing, of course.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
correct way to create dynamically function pointers Hello World <acidlategamer@gmail.com> - 2017-04-11 10:20 -0700
Re: correct way to create dynamically function pointers scott@slp53.sl.home (Scott Lurndal) - 2017-04-11 17:34 +0000
Re: correct way to create dynamically function pointers Hello World <acidlategamer@gmail.com> - 2017-04-11 10:42 -0700
Re: correct way to create dynamically function pointers scott@slp53.sl.home (Scott Lurndal) - 2017-04-11 17:48 +0000
Re: correct way to create dynamically function pointers Hello World <acidlategamer@gmail.com> - 2017-04-11 10:55 -0700
Re: correct way to create dynamically function pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-11 19:06 +0100
Re: correct way to create dynamically function pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-11 14:23 -0400
Re: correct way to create dynamically function pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-11 19:05 +0100
Re: correct way to create dynamically function pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-11 14:11 -0400
Re: correct way to create dynamically function pointers Richard Heathfield <rjh@cpax.org.uk> - 2017-04-12 08:27 +0100
Re: correct way to create dynamically function pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-12 13:31 -0400
Re: correct way to create dynamically function pointers Richard Heathfield <rjh@cpax.org.uk> - 2017-04-12 23:05 +0100
Re: correct way to create dynamically function pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-11 19:03 +0100
Re: correct way to create dynamically function pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2017-04-11 14:05 -0400
Re: correct way to create dynamically function pointers Jorgen Grahn <grahn+nntp@snipabacken.se> - 2017-04-15 10:19 +0000
Re: correct way to create dynamically function pointers asetofsymbols@gmail.com - 2017-04-15 05:09 -0700
Re: correct way to create dynamically function pointers Barry Schwarz <schwarzb@dqel.com> - 2017-04-11 15:13 -0700
Re: correct way to create dynamically function pointers Richard Heathfield <rjh@cpax.org.uk> - 2017-04-12 08:28 +0100
Re: correct way to create dynamically function pointers Richard Heathfield <rjh@cpax.org.uk> - 2017-04-12 08:19 +0100
Re: correct way to create dynamically function pointers Spiros Bousbouras <spibou@gmail.com> - 2017-04-12 21:17 +0000
Re: correct way to create dynamically function pointers Richard Heathfield <rjh@cpax.org.uk> - 2017-04-12 23:11 +0100
Re: correct way to create dynamically function pointers Keith Thompson <kst-u@mib.org> - 2017-04-12 16:36 -0700
Re: correct way to create dynamically function pointers John Bode <jfbode1029@gmail.com> - 2017-04-12 10:04 -0700
Re: correct way to create dynamically function pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-04-12 19:28 +0100
Re: correct way to create dynamically function pointers Tim Rentsch <txr@alumni.caltech.edu> - 2017-04-17 05:50 -0700
csiph-web