How do I create a function in my library for passing user callback function

B

Ben Bacarisse

Bill Reid said:
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.
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.

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.


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").

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.

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.
 
B

Bill Reid

Ben Bacarisse said:
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!??!!!)..
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...
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"...
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"...
 
B

Ben Bacarisse

Bill Reid said:
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...

It certainly is a special case. If I have a parameter that is
declared 'double **param' I can save it in a variable declared 'double
**var'. Even if it is of type 'void (*param)(char *)' I can save it
in local variable declared 'void (*var)(char *)'. But a parameter
declared 'void param(char *)' needs... You get the picture.
 
Y

ymuntyan

That's fine, but I would not suggest it as a "first example" or in
"how to" code just because it needs more explanation.



Again, that is up to you, but in my editor copying the prototype is
fewer keystrokes than writing the two forms you used.





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").




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.

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.

And the posters who declare "syntax error stupid", should
at least see if their compiler agrees.
At least some of the "fuzz" here may have come from
your use of two different styles.

My hypothesis is: Bill didn't write that stuff intentionally.
He meant to write a pointer or whatever, doesn't matter what.
But he happened to write *correct* code, and then was told
three times (two in great details about how dumb he is
making that mistake and not seeing and admitting it) he has
a syntax error there. What's the real cause of the "fuzz"
again?

A troll? Don't feed the troll, how about that! BS, in other
words.

Yevgen
 
B

Bill Reid

My hypothesis is: Bill didn't write that stuff intentionally.
He meant to write a pointer or whatever, doesn't matter what.
But he happened to write *correct* code,

Yeah, correct code happens "by accident", riiiiiiiiight...I almost
forgot I'm in the group that is so statistically incompetent that it
believes you can win a casino gambling game by doubling your
bet on every loss...
and then was told
three times (two in great details about how dumb he is
making that mistake and not seeing and admitting it) he has
a syntax error there.

But there was NO "syntax error", you know that!!! What the hell is
the matter with you, afraid of the big bad trolls?!??! THEY'RE STUPID
PUNKS, PERIOD, THE ONLY CREDIBILITY THEY HAVE IS WHAT
YOU GIVE THEM BECAUSE YOU'RE AN EVEN STUPIDER
PUNK THAN THEY ARE.
A troll? Don't feed the troll, how about that!

Exactly! So why do you keep feeding "Little Dick" and
"troll-ettes"? Ignore them, or mock them, whatever, the
thing about trolls is they never CAN change their defective
behavior, so just have a little fun by laughing at their
pathetic lives or pass 'em by and have some more
productive fun somewhere else, it's all the same, but
NEVER LET THEM CONTROL YOU...

You KNOW they are LYING about "errors" and "bugs"; otherwise
they are just technically incompetent, take your pick, maybe mix
and match. A troll is somebody who DELIBERATELY lies to provoke
a newsgroup into an unproductive flame-war, and generally ducks
out early to sit back and watch the "fun".

Who're the LIARS here, and who LIED AND RAN?!??!

Don't feed the trolls indeed; actually, I'm sorry I answered THIS
completely DUMBASS post...
 
N

Nick Keighley

Wouldn't you know it, this tool posts from Google(TM) Groups...

"tool"? Is this sort of language necessary?

HEY, FOOL, IF YOU'RE GONNA BE SUCH AN IDIOT AS TO
POST FROM THE SCOURGE OF USENET, AT LEAST LEARN
HOW TO DO IT SO YOUR POSTS ARE QUOTED PROPERLY!!!

I'm genusinely curious. In what way have I misquoted? I've
been quoting in usenet in this manner for some time and
assumed it was a well known quoting convention.
And one that *most* people use.

All upper case is often regarded as rude. But then I suspect
you know that. :)

TIA!!!  (but really, not holding my breath waiting for him to learn
how to post to Usenet...that's too "technical")

So explain.

<attributions moved to top of post>

Maybe it's a mistake to NOT include it...I know this is hard,
but THINK...

Nope sorry. You use the convention. I don't. I have been using my
convention for quite some time and I'm quite happy with it.
Merely admonishing me to think won't help. I've thought.

So do you have a good reason to include the extern?
I thought you liked to save typeing!

Have you ever heard of a guy named Eric Naggum?

OK, you're right, you don't have to THINK about anything at all
when programming...oh, that's right, you DO have to think when
programming, just not when posting to the Internet...

Ah, you seem to have misunderstood. I meant I've never found
getting the signature right for callbacks was particularly
difficult, not that thinking whilst programming was unnecessary.

It's hard to understand how you could have made this mistake.

--- unquoted tool text ---
is *what* the error I mentioned? The error above occurs on
the line I indicated.
--- end tool text

You seem to be using a very unusual quoting convention.
Is there an RFC for it?

He's asking you why your compiler reports an error, since his
may not under the same circumstances, you massive tool...

I didn't know his compiler didn't produce a diagnostic.

here's my REALLY
compact version of the code THAT COMPILES COMPLETELY
CLEANLY FOR ME:

ah, I wasn't aware that some compilers didn't issue a diagnostic.
Which compiler is it and do you have warnings set to their
highest level? This is a good practice.

<snip>

This is a technical news group there really isn't any
point in getting so wound up. Perhaps less coffee in future?
 
N

Nick Keighley

Hi Bill,

It appears I was mistaken (ie. wrong) in thinking your code
had a syntax error. I apologise.

In future I should check the standard and not trust my (aged)
compiler.

On a style note I prefer the use of a typedef (it even saves
typeing).

typedef int (*Callback_func) (const char*);

int callback_user (Callback_func callback)
{
int retval;
retval = callback ("pippo");
return retval;
}
 
N

Nick Keighley

Nick Keighley said:



I prefer not to hide the pointeriness in the type:

typedef int Callback_func(const char *);

but rather to make it explicit in the prototype:

int callback_user (Callback_func* callback)

That's why I use the *_func convention.
But this is sailing close to hungarian.
And I dislike other examples of hidden pointers.
So I may change to your convention.


--
Nick Keighley

"Programs must be written for people to read, and only
incidentally for machines to execute."
- Abelson & Sussman, Structure and Interpretation of Computer Programs
 
B

Ben Bacarisse

On Apr 14, 7:07 pm, Ben Bacarisse <[email protected]> wrote:

My hypothesis is: Bill didn't write that stuff intentionally.
He meant to write a pointer or whatever, doesn't matter what.
But he happened to write *correct* code,

That seems a little unfair. He says that he prefers the syntax in
definitions because it saves '(*)' and he uses '(*)' in prototypes
because it is shorter and avoids a (technically) redundant name and I
don't see any reason not to believe that.
and then was told
three times (two in great details about how dumb he is
making that mistake and not seeing and admitting it) he has
a syntax error there. What's the real cause of the "fuzz"
again?

A troll? Don't feed the troll, how about that! BS, in other
words.

I don't understand this. Bill Reid has an angry, aggressive style
that means I often skip his posts, but I never called him a troll.
 
R

Richard

Richard Heathfield said:
Nick Keighley said:


So was I (cf <[email protected]>)



I prefer not to hide the pointeriness in the type:

typedef int Callback_func(const char *);

but rather to make it explicit in the prototype:

int callback_user (Callback_func* callback)

Agreed 100%. Easy "at a glance" signalling of pointer usage.
 
C

Charlton Wilbur

BR> Yeah, correct code happens "by accident", riiiiiiiiight...I
BR> almost forgot I'm in the group that is so statistically
BR> incompetent that it believes you can win a casino gambling
BR> game by doubling your bet on every loss...

[...]

BR> But there was NO "syntax error", you know that!!! What the
BR> hell is the matter with you, afraid of the big bad trolls?!??!
BR> THEY'RE STUPID PUNKS, PERIOD, THE ONLY CREDIBILITY THEY HAVE
BR> IS WHAT YOU GIVE THEM BECAUSE YOU'RE AN EVEN STUPIDER PUNK
BR> THAN THEY ARE.

[snip about as much more of a rant]

In matters technical, where there's a right answer and a wrong answer,
there's rarely a need to get this worked up. If you're right, that
will show itself soon enough, and, well, if you're wrong, that will
too. All this level of insult and hyperbole manages to do is make you
look like an ass. Is that what you're trying to accomplish?

Charlton
 
B

Bill Reid

Look, I am not going to manually quote your messed-up post
from googlegroups.com (I actually just don't bother to respond
to these types of posts because they rarely have anything
intelligent in them in the first place in addition to the quoting
problem), but I'll make a few points:

1. Don't ask me how to use Google(TM) Groups to get
posts that are quoted properly when I try to respond to them,
because I don't use that piece of crap server, I have an
actual non-library computer of my own, and a real ISP
account with a real news server and use a real, if not
particularly good, newsreader. All I know is that SOME
posts from googlegroups.com are not quoted properly
when I try to respond to them, BUT OTHERS ARE,
so it's something YOU are doing differently from other
idiots who use googlegroups.com...and yes, I generally
just assume everybody who posts from googlegroups.com
is an idiot, just like the old method of looking for "webtv"
or "aol" as the posting host...and furthermore, googlegroups.com
is single-handedly destroying Usenet and must be stopped
(well, maybe not MUST, because actually who cares)...more
on this at the end of this post...

2. extern = EXPLICIT, I know what I'm TRYING to do

3. If you haven't had to think carefully about exactly what
data you want to pass to a callback, you are very inexperienced
using callbacks, sorry...your toy program writing background
is showing again...

4. Hey, what compiler are YOU using? I have three warning
levels on mine: None, Selected (whatever that means), and
All (I usually use the default, "Selected"). None of them produce
a warning for that code, and if it did, I'd consider getting a new
compiler, because I have no use for a warning about something
that could NEVER EVER POSSIBLY BE A PROBLEM. Just
about all of the warnings I do get are useful, because they do
properly warn me that I MAY be doing something dangerous,
but that is not the case here...and I'll bet there aren't a lot
of compilers out there that are so brain-dead they can't
recognize perfectly legal STANDARD equivalent declarations
properly, I'm not even sure you just didn't FAKE your so-called
"error"...

5. As a technical newsgroup I expect technically accurate
responses, or short PRODUCTIVE RESPECTFUL discussions
to resolve any "discrepancies"...unfortunately, that's not the
"posting style" of a lot of the frequent posters here.

6. I'm not swiching to decaf.

7. DIE GOOGLE(TM) DIE!!!

I'm going to re-print a post I made in another group the other day;
this is my vainglorious attempt (probably in vain) to "save Usenet";
"aol" is largely just a bad memory, "webtv" is still around a little
bit as the official posting host of toofless hillbillies, now it's time
to take out the trash of Google(TM), let's try at least:

From: "Bill Reid" <[email protected]>
Newsgroups: misc.invest.stocks
Subject: Re: Would there be any support for a moderated group???
Date: Sun, 13 Apr

This used to be a fun groupSSthere was a lot of info exchanged by
participants ranging from the well-informed to the terminally
cluelessSSthere was give-and-take, humor, arguments, theories, etc.
What¹s dominating the N/G now??? Ads for Chinese ripoffs, pure bigotry,
forex can¹t-lose systems, cross-postings from political whackos, psychotic
venting & threats, kiddies with $6 get-rich schemes, etc.SS.
I don¹t know whatOs involved in a moderated group or if they even
workSSIs there anyone here that can shed some informed light on the
subject???

Forget it "Blash", it's UsenetTown...

Having gone through this exact thing with other newsgroups that
USED to be focal points of ON-TOPIC conversation about a specific
subject, I know for a fact that a moderated group will probably
NOT work, because it didn't for the other groups. They went through
the whole voting process, got the server, moderator(s), within a
year the moderated group was dead as well and the original
group was just a wasteland of spam...

Remember, I've repeatedly set out the timeline for the ultimate
demise of this group, and we're right on schedule. It's not JUST
the spammers; the death knell is the arrival of completely demented
fakes that sock-puppet each other and form a "voting block" to drive
away any intelligent posters with constant insane repugnant behavior
(sound familiar?). THAT'S the "gating factor" that can predict to a
matter of months the death of the group...again, I speak from
previous experience, you REALLY don't want to know the gory
details...

In a larger sense, Usenet itself is just a manifestation of the
old theory of "The Tragedy Of The Commons" (the idea that
"communism" can NEVER "work"), that a shared resource
that should be used responsibly by all people WILL ultimately
be destroyed by the lowest common denominator.

It also follows my general management principle, which SHOULD
be the foundation for all businesses and "capitalism" as a
whole, that when you divorce RESPONSIBILITY from AUTHORITY
you get chaos, not anything remotely resembling the "invisible
hands" that apologists for "capitalism" like to yammer about.
ANYBODY has the "authority" to post here, whether "homeless",
briefly un-incarcerated mentally-ill, ex-con, Chinese shoe spammer,
whatever, but accept NO "responsibility" to behave in a respectful
productive manner.

BUT...here's a slightly different idea, from a long time ago (in
Internet years). There used to be a concept called the "Usenet
Death Penalty", where a Usenet server that was providing a free
reign to spammers and/or loonies would be "removed" from
Usenet by mutual agreement of the major server operators.
They would just stop picking up posts from the outlaw server,
and that would effectively stop the problem in its tracks;
NOBODY who didn't use that server would ever see posts
from that server again...PROBLEM SOLVED!!! But I'm not
sure what the current status of that "system" is...

But we all know where 95% of today's problems originate, it's
called "Google(TM) Groups". Check the "Path" of a Chinese shoe
spammer or insane mongoloid, and it almost certainly will end
like this (signifying that is the original server that the creep posted
to):

Path:
<your_server>!<server_your_server_copied_post_from!server_that_server_copied
_post_from!and_so_forth!...!...!postnews.google.com!e67g2000hsa.googlegroups
..com!not-for-mail

(the above is an edited header from a "BuffyTheProfitHater" post)

Unfortunately, my newsreader, and many other newsreaders, do
not support "killfiling" a post by the original server, but this is
definitely
something that can be done at the "client" level, so if you have this
capability and are bothered by Chinese spammers and loonies
just "killfile" "googlegroups.com" and you're sailing clear seas
again...

OK, failing that, here's another idea: KILL Google(TM). No,
not "killfile" "googlegroups.com", not the "Usenet Death Penalty"
for "googlegroups.com", I MEAN KILL THE FRIGGIN' COMPANY
GOOGLE...DEAD!!!

Google(TM) STILL derives MOST of its revenue from those little
links they identify as "sponsored links" in your search results.
IF YOU DON'T CLICK ON THOSE LINKS, GOOGLE(TM) GOES
OUT OF BUSINESS (until they wise up and hide the "sponsored
links" in the sea of search results, which they've already started
doing a little bit as their "paid click rates" have gone down
recently).

You DON'T have to click on those links; I've almost never clicked
on them, and I use Google(TM) search all the time, and use it to
book hotels, airline tickets, etc., BUT I CLICK ON AN IDENTICAL
UN-SPONSORED LINK RIGHT BELOW THE SPONSORED
LINK...THEY'RE THE SAME DAMN LINK, BUT GOOGLE(TM)
DOESN'T GET ANY MONEY FOR IT (or shouldn't)!!!

So here's what you do; send a complaint e-mail about whatever
it is in this group that you don't want to see that is coming from
"googlegroups.com" to this address:

Complaints-To: (e-mail address removed)

Word is that they COMPLETELY ignore all mail sent to that
address (the same way Netscape used to ignore all bug-mail,
remember them?), but in addition to specifying the specific
types of posts that are ruining Usenet for you, make sure you
let them know that until THEY take RESPONSIBILITY for
the spam and threats and slander, you will do what you can
to PUT THE ENTIRE DAMN COMPANY OUT OF BUSINESS.

They almost certainly will STILL ignore it, but I always like
watching companies die anyway ("creative destruction") so
what the hell, let's kill 'em dead and make room for the next
flash-in-the-pan Internet company...and if they actually do
something, it will be fun to watch "Lowbrow" scramble for
another free way to entertain us with his idiocy...
 
R

Richard

Bill Reid said:
4. Hey, what compiler are YOU using? I have three warning
levels on mine: None, Selected (whatever that means), and
All (I usually use the default, "Selected"). None of them produce
a warning for that code, and if it did, I'd consider getting a new
compiler, because I have no use for a warning about something
that could NEVER EVER POSSIBLY BE A PROBLEM. Just
about all of the warnings I do get are useful, because they do
properly warn me that I MAY be doing something dangerous,
but that is not the case here...and I'll bet there aren't a lot
of compilers out there that are so brain-dead they can't
recognize perfectly legal STANDARD equivalent declarations
properly, I'm not even sure you just didn't FAKE your so-called
"error"...


Possibly Nick should consider trying things out rather than relying on
the new vogue in c.l.c which is "power analysis" of 10 foot high
printouts. Me? I regularly check code with "splint" as well as use
pedantic modes in gcc. Here's a little bit of "splint" integration for
emacs that I knocked up recently ....

,----
| (defun do-lint()
| (interactive)
| (set (make-local-variable 'compile-command)
| (let ((file (file-name-nondirectory buffer-file-name)))
| (format "%s %s %s"
| "splint"
| "+single-include -standard -preproc -I/usr/include/gtk-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/cairo/ -I/usr/include/pangomm-1.4/pangomm/"
| file
| )))
| (message compile-command)
| (compile compile-command)
| )
|
`----

Sure, not ISO Standard C, but gives some hints to fellow programmers
about how best to proceed before huffing and puffing in this NG like a
member of the Reform Club who has just discovered that they have changed the
Port supplier in addition to allowing "foreigners" in ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top