Re: How do I create a function in my library for passing user callback function
- From: "Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx>
- Date: Tue, 15 Apr 2008 01:01:05 GMT
Ben Bacarisse <ben.usenet@xxxxxxxxx> wrote in message
news:87iqykasl5.fsf@xxxxxxxxxxxx
"Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx> writes:
Ben Bacarisse <ben.usenet@xxxxxxxxx> wrote in message<snip>
news:87bq4cci3r.fsf@xxxxxxxxxxxx
"Bill Reid" <hormelfree@xxxxxxxxxxxxxxxx> writes:
<snip lots>
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.
Sure it is. I use it all the time, so it's normal to me.
That's fine, but I would not suggest it as a "first example" or in
"how to" code just because it needs more explanation.
OK, that's sort of fair; as I've said, I'm all about helping
the "newbies" (won't SOMEBODY think of the children!??!!!)..
Usually, the
function definition is similar to the declaration, except the ';' is
replaced by the function body.
Right. Let me clue you in on something about me: I try to
conserve keystrokes where they AREN'T needed, and use
them where they help me understand my own code.
Again, that is up to you, but in my editor copying the prototype is
fewer keystrokes than writing the two forms you used.
Uh-oh, I knew it would come to this...time and motion on
key-presses...now I'm in REAL trouble...preparing to back-pedal...
<snip>
Function pointer parameters usually look like this:
void my_library_function(int (*my_callback_function)(const char*)) {}
Sure. But then I have to type "(*)" (three whole extra characters!)
where I don't need to type any more characters, because the two
ways of defining the parameters ARE TOTALLY FUNCTIONALLY
IDENTICAL.
which is, of course, how you wrote it in the function's prototype.
There, I'm forced to write it that way, unless I again want to
type unwanted characters...WHICH I DON'T.
This I don't get. You can save two keystrokes if you use the same
style in the prototype (but let me guess: a parameter name in a
prototype is "unwanted characters").
Well, yeah...also, as you might guess, we ALL have our
little peccadillos, and I HATE parameter names in prototypes,
and I'm sure I could find a compiler or LINT someplace that
would issue a warning agreeing with my childhood toilet-training
trauma, the same way the "troll-ette" found HIS compiler
that unearthed MY "error"...
<snip>
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''
Great, which of course completely conforms to the basic
idea above that a function name is actually a function pointer
by the simple necessity of computer science...I'm assuming
this is "standard" language, so despite you calling it a
"special dispensation" IT IS TOTALLY CONFORMING
"STANDARD" SYNTAX.
Yes, but that does not make it good syntax. With your example, a
beginner would wonder why a variable declared to store this callback
pointer looked so different to the parameter that receives it. C has
enough special cases already.
Again, I don't even consider, or was aware, it a "special case", but
rather just another manifestation of the general case regarding function
pointers...
I'm sure the OP has run away in terror by now, but PART of his
problem seemed to be not understanding that basic concept...and
there was no post except mine that demonstrated it (actually, if
you read his post, he was REALLY confused about the whole
concept of "callbacks", and NOBODY posted anything coherent
to clear ANY of that confusion EXCEPT me)...
I don't want to have a style war about how you write your programs,
but in "how to" postings I would suggest being consistent and avoiding
special cases. At least some of the "fuzz" here may have come from
your use of two different styles.
Nah, the real problem is that it's always easier to be a critic than
an artist...like I say, programming I'm not that good at, it's PEOPLE
that I really know "inside-out"...
---
William Ernest Reid
.
- Follow-Ups:
- Re: How do I create a function in my library for passing user callback function
- From: Ben Bacarisse
- Re: How do I create a function in my library for passing user callback function
- 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
- Re: How do I create a function in my library for passing user callback function
- From: Ben Bacarisse
- 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: Ben Bacarisse
- 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: why cant functions return arrays
- 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
|