OOP in C!

  • Thread starter Prashanth Ellina
  • Start date
M

Malcolm

E. Robert Tisdale said:
You have never provided a single reason
why you believe that these are not callback functions.
I submit that the reason is that you can't
and that you know that you can't.
They are not callback functions because they are not passed by a high-level
function to a lower-level one, and then called.

The vast majority of C function pointers are used to implement callback
functions, but not all of them.
You are simply trolling.
Please go away troll.
Can people (Not just E. Robert Tisdale) please stop filling the ng with
"troll alerts", accusations of trolling, etc. Most of the regs are not
interested.
 
E

E. Robert Tisdale

Something said:
A function pointer is by definition a callback function.

You are a liar.
I never said any such thing.
I merely asked for an example of a function pointer
that is not used as a callback function.
So far, you have failed to provide one.
 
C

Christian Bau

In typical Tisdale manner, a falsified quote.
You are a liar.
I never said any such thing.
I merely asked for an example of a function pointer
that is not used as a callback function.
So far, you have failed to provide one.

Go away, idiot.
 
C

Christian Bau

"Malcolm said:
They are not callback functions because they are not passed by a high-level
function to a lower-level one, and then called.

The vast majority of C function pointers are used to implement callback
functions, but not all of them.
Can people (Not just E. Robert Tisdale) please stop filling the ng with
"troll alerts", accusations of trolling, etc. Most of the regs are not
interested.

I think this is a misunderstanding.

It is not an accusation. It is the troll Tisdale, in this case replying
to Arthur J. O'Dwyer, and he is friendly enough to alert Arthur that
this is a post from a troll.
 
M

Malcolm

E. Robert Tisdale said:
I merely asked for an example of a function pointer
that is not used as a callback function.
So far, you have failed to provide one.
OK here's an example.

/*
return the maximum value of an stdlib maths function that takes one scalar
as its argument.
*/
double maximum( double (*fptr)(double x) )
{
if( fptr == sin)
return 1.0;
if(fptr == sqrt)
return DBL_MAX;
if(fptr == asin)
return 3.14 * 2.0;

/* add extra for the other function in the maths library */
}
 
M

Me

Please don't waist your time trying to be OO using C...

Just move to C++ man...

The code I am porting right now does that and it sucks....

Write OO in an OO language and get AWAY from non OO except for drivers and
such.
 
E

E. Robert Tisdale

Malcolm said:
OK here's an example.
> cat example.c
#include <math.h>
#include <float.h>

// return the maximum value of an stdlib maths function
// that takes one scalar as its argument.

double maximum(double (*fptr)(double x)) {
if( fptr == sin)
return 1.0;
if(fptr == sqrt)
return +DBL_MAX;
if(fptr == asin)
return 3.14 * 2.0;
return -DBL_MAX;

// add extra for the other function in the maths library
}
> gcc -Wall -std=c99 -pedantic -c example.c

Contrived and silly but correct.
 
R

Richard Tobin

E. Robert Tisdale said:
I merely asked for an example of a function pointer
that is not used as a callback function.

A function is a callback when it calls *back*. So if you pass a
function pointer to a library, and the library calls it, then it's
reasonable to call it a callback.

Many uses of function pointers aren't like that.

For example, an interpreter that uses a table to map function names
to function pointers.

Or a struct that contains a function pointer representing a method
(you might consider it a callback if it's set "from outside", but not
if it's just set by the constructor).

Or a function pointer used in an expression, such as

return (size < threshhold ? quickalloc : slowalloc)(size, heap);

Ot a function pointer used for calls to dynamically loaded functions
(obviously not pure standard C).

-- Richard
 
A

Alan Balmer

OK here's an example.

/*
return the maximum value of an stdlib maths function that takes one scalar
as its argument.
*/
double maximum( double (*fptr)(double x) )
{
if( fptr == sin)
return 1.0;
if(fptr == sqrt)
return DBL_MAX;
if(fptr == asin)
return 3.14 * 2.0;

/* add extra for the other function in the maths library */
}
And, of course, function pointers are a well-known approach to
implementing state machines.
 
E

E. Robert Tisdale

Richard said:
A function is a callback when it calls *back*.
So, if you pass a function pointer to a library
and the library calls it,
then it's reasonable to call it a callback.
Agreed.

Many uses of function pointers aren't like that.

For example, an interpreter that uses a table
to map function names to function pointers.

What about Stephen Sprunk's parsing example upthread?

"Since the command selector is a string,
it can't be used in a switch statement,
and keeping the list of commands and their respective parsers
in an array also makes it very easy to add and remove commands
without touching the core logic.
And, since the list of commands is stored outside said logic,
it also allows different users
to get a different list of valid commands
(or the same commands pointing to different parsers)
just by passing in a different array to the same core logic."

Because the function table

struct parser_record parser_table_user[] = {
{ "FOO", parse_foo },
{ "BAR", parse_bar },
{ "BAZ", parse_baz },
{ NULL, NULL}
};

can be defined in the calling program and passed to parse_main,
the functions (parse_foo, parse_bar and parse_baz)
are callback functions.
Or a struct that contains a function pointer representing a method
(you might consider it a callback if it's set "from outside",
but not if it's just set by the constructor).

It is a callback function
if you pass a reference (pointer) to that struct to another function
which calls it through the pointer set by the constructor.

The bottom line is that pointers to callback functions can be used
to implement run-time polymorphism in C as well as C++.
The code written to operate on object of a "base" type
will still work with objects "derived" from the base type
because it can callback the functions implemented for
the derived type through the function pointers
in the virtual function table (jump table).
 
C

Christian Bau

pete said:
Would this be on topic in comp.programming?

The discussion was about the local troll claiming that "function
pointers" and "callback functions" are the same thing. Which is
nonsense, and I think refuting it is on-topic in comp.lang.c.
 
E

E. Robert Tisdale

Something said:
The discussion was about the local troll

That's a lie.
There was no such discussion.
claiming that "function pointers" and "callback functions"
are the same thing.

That's a lie. No one ever claimed that
"function pointers" and "callback functions" are the same thing.
Which is nonsense,
and I think refuting it is on-topic in comp.lang.c.

Of course it's nonsense.
It's a *straw man* that you made up.

You are a liar an a troll Christian.
Go away troll.
 
C

Christian Bau

"E. Robert Tisdale said:
That's a lie.
There was no such discussion.


That's a lie. No one ever claimed that
"function pointers" and "callback functions" are the same thing.


Of course it's nonsense.
It's a *straw man* that you made up.

You are a liar an a troll Christian.
Go away troll.

You are so funny. The thing is, everyone can check that this discussion
started with _you_ "correcting" a poster who used the term "function
pointer" and replacing it with "callback function". The only difference
to your usual behavior was that the original poster actually _did_ write
"function pointer", so this time you didn't have to forge a quote to be
able to add a "correction".
 
E

E. Robert Tisdale

Christian said:
You are so funny. The thing is, everyone can check that
this discussion started with _you_
"correcting" a poster who used the term "function pointer"
and replacing it with "callback function".

That's another lie.
The only difference to your usual behavior was that
the original poster actually _did_ write "function pointer",
so this time you didn't have to forge a quote
to be able to add a "correction".

That's another lie. If you weren't lying,
you would have identified and quoted this "original poster".
But no one ever said any such thing.
You simply fabricated this lie to perpetuate your troll.

Go away troll.
 
R

Richard Tobin

For example, an interpreter that uses a table
to map function names to function pointers.
[/QUOTE]
What about Stephen Sprunk's parsing example upthread?

You *might* consider those functions to be callbacks, but only because
they can be passed in by the user:
And, since the list of commands is stored outside said logic,
it also allows different users
to get a different list of valid commands
(or the same commands pointing to different parsers)
just by passing in a different array to the same core logic."

But that's just a feature of the particular example. The
callback-ness in this case is just an add-on to a common non-callback
use of function pointers.
It is a callback function
if you pass a reference (pointer) to that struct to another function
which calls it through the pointer set by the constructor.

That seems to be stretching the definition beyond the point of
usefulness. The essence of a callback is that you (the user of some
library) call a function, and it calls you back. It's not usually
used for the case where a library gives you a function to call.
The bottom line is that pointers to callback functions can be used
^^^^^^^^
to implement run-time polymorphism in C as well as C++.
The code written to operate on object of a "base" type
will still work with objects "derived" from the base type
because it can callback the functions implemented for ^^^^^^^^
the derived type through the function pointers
in the virtual function table (jump table).

I find that paragraph reads more naturally if you remove the first
"callback" and replace the second with "call".

-- Richard
 
E

E. Robert Tisdale

Richard said:
E. Robert Tisdale wrote:



You *might* consider those functions to be callbacks,
but only because they can be passed in by the user:


But that's just a feature of the particular example.
The callback-ness, in this case, is just an add-on
to a common non-callback use of function pointers.


That seems to be stretching the definition
beyond the point of usefulness. The essence of a callback is that
you (the user of some library) call a function, and it calls you back.

Meaning that the library function calls a function that you,
the library user, provided for the library function to callback.
It's not usually used for the case
where a library gives you a function to call.

I never argued that the callback function was provided by the library.
I find that paragraph reads more naturally if you remove the first
"callback" and replace the second with "call".

Still, the essential feature of [virtual] functions
is that they are callback functions.
 
A

Andrew

That's another lie.

-----
From: "E. Robert Tisdale" <[email protected]>
Newsgroups: comp.lang.c
Subject: Re: OOP in C!
Date: Thu, 03 Jun 2004 17:35:13 -0700
Organization: Jet Propulsion Laboratory
Lines: 105
Message-ID: <[email protected]>
References: <[email protected]>
Reply-To: (e-mail address removed)
NNTP-Posting-Host: penguin.jpl.nasa.gov
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: nntp1.jpl.nasa.gov 1086309307 4531 137.78.73.121 (4 Jun 2004
00:35:07 GMT)
X-Complaints-To: (e-mail address removed)
NNTP-Posting-Date: 4 Jun 2004 00:35:07 GMT
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6)
Gecko/20040510
X-Accept-Language: en-us, en
In-Reply-To: <[email protected]>
Xref: cyclone01.bloor.is.net.cable.rogers.com comp.lang.c:152405
X-Received-Date: Thu, 03 Jun 2004 21:00:40 EDT
(news04.bloor.is.net.cable.rogers.com)

Prashanth said:
I have a feeling that [Obect Oriented Programming] can be done in C also.
Correct.

I have used a structure to hold member variables and function pointers.

Pointers to *callback* functions.

-----

Does Tisdale ever actually read the crap he's typing? Or does he have
an ignore mode he turns on every time he writes a follow-up, so that
when it's later mentioned, he can call people liars?

And why does he insist on changing the subject line so much? It's
annoying.

Oh well, maybe the next one will be "Andrew is a lying troll", despite
the abundance of evidence that would indicate, in Tisdale's case, that
is a pot calling the kettle black situation.
That's another lie. If you weren't lying,
you would have identified and quoted this "original poster".
But no one ever said any such thing.
You simply fabricated this lie to perpetuate your troll.

Go away troll.

....
 
I

Irrwahn Grausewitz

[In response to typical Trollsdale tripe]

Does Tisdale ever actually read the crap he's typing? Or does he have
an ignore mode he turns on every time he writes a follow-up, so that
when it's later mentioned, he can call people liars?

And why does he insist on changing the subject line so much?
<snip>

Commonly, the adequate answer to such questions would be to cite
Hanlon's Law, but given Trollsdales record his acting seems to be
driven by pure maliciousness.
Oh well, maybe the next one will be "Andrew is a lying troll",
<snip>

If so, I suggest you take it as a compliment. Usually only sensible
people are attacked by Edwin Trollstale.

Regards
 
C

CBFalconer

Andrew said:
.... snip ...

Does Tisdale ever actually read the crap he's typing? Or does he
have an ignore mode he turns on every time he writes a follow-up,
so that when it's later mentioned, he can call people liars?

I think he is still trying to attain the mental status of the long
line of gnats he is following.
And why does he insist on changing the subject line so much?
It's annoying.

As is Trollsdale. In this case it is possible his large brain
(for gnats) believes it hides the thread out of which it grew.

Query: By how many micrograms does the weight of two mature
statistically average gnat brains exceed that of the functional
portion of Trollsdales brain. (This was never properly debated on
Cheers).
 

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

Similar Threads

Pointer casts for OOP 2
C exercise 1
Meme generator in c 1
Copy string from 2D array to a 1D array in C 1
OOP 13
Filter sober in c++ don't pass test 0
[C#] Extend main interface on child level 0
Learning OOP 1

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top