Re: How do I create a function in my library for passing user callback function
- From: Ben Bacarisse <ben.usenet@xxxxxxxxx>
- Date: Mon, 14 Apr 2008 21:11:03 +0100
"Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx> writes:
<snip lots>
Why do you have to be so angry? There is a technical matter here so I
will get stuck in, but I am wary of getting caught in the middle of a
flame war.
... that's his conception about how function
pointers work, and basically mine...so here's my REALLY
compact version of the code THAT COMPILES COMPLETELY
CLEANLY FOR ME:
library_h.h
extern void my_library_function (int (*)(const char*));
library_c.c
#include "library_h.h"
void my_library_function(int my_callback_function(const char*)) {
}
You must be aware that is this not the normal syntax. Usually, the
function definition is similar to the declaration, except the ';' is
replaced by the function body. Here, you have an odd-looking
parameter. Function pointer parameters usually look like this:
void my_library_function(int (*my_callback_function)(const char*)) {}
which is, of course, how you wrote it in the function's prototype.
This example *seems* to declare the parameter as a function, not a
pointer to one.
I can compile library_c.c to library_c.obj without so much as
a warning, error, scolding, and then proceed likewise to build
library.lib...so in the interest of everybody learning something
today, other than you're a tool who doesn't know how to post
to Usenet, EXPLAIN THE DISCREPANCY..."spec lawyer" it,
tell us exactly what you did differently, whatever, just clear up
the confusion here...
The answer is that there is a special dispensation:
A declaration of a parameter as ‘‘function returning type’’ shall be
adjusted to ‘‘pointer to function returning type’’
This is the same sort of special case that makes 'int x[]' be treated
as a pointer rather than an (un-passable) array. Your example is less
than clear for people learning the language or having trouble with
function pointers. I would not post it as an example to follow, but
it is correct.
--
Ben.
.
- Follow-Ups:
- References:
- How do I create a function in my library for passing user callback function
- From: Angus
- Re: How do I create a function in my library for passing user callback function
- From: Bill Reid
- Re: How do I create a function in my library for passing user callback function
- From: Nick Keighley
- Re: How do I create a function in my library for passing user callback function
- From: ymuntyan
- Re: How do I create a function in my library for passing user callback function
- From: Nick Keighley
- Re: How do I create a function in my library for passing user callback function
- From: Bill Reid
- How do I create a function in my library for passing user callback function
- Prev by Date: Re: #define for very small numbers ?
- Next by Date: Re: Network modules
- Previous by thread: Re: How do I create a function in my library for passing user callback function
- Next by thread: Re: How do I create a function in my library for passing user callback function
- Index(es):
Relevant Pages
|