473,408 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

callback functions

Is it possible to write a function that, once called, is executed
together with the caller without stopping it? I've seen such functions
in windows programming, using CALLBACK qualifier before the function
name (is it a macro?). Now I would like to know if this could be
possible in standard C, maybe using some tricks. And going a little ot..
what other non-standard ways to do that do you know?

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Nov 15 '05 #1
5 2533
DevarajA wrote on 03/09/05 :
Is it possible to write a function that, once called, is executed together
with the caller without stopping it? I've seen such functions in windows
programming, using CALLBACK qualifier before the function name (is it a
macro?). Now I would like to know if this could be possible in standard C,
maybe using some tricks. And going a little ot.. what other non-standard ways
to do that do you know?


Callbacks have nothing to do with concurrent ('executed together ')
functions. They are just user functions called by some lower level
function (system, library...) See the standard qsort() function and its
'compare' callback.

If you want concurrent (well, sort of) execution, you want processes or
threads. Theses are beyond the scope of the C-language. Ask a newsgroup
dedicated to your system.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
Nov 15 '05 #2
Emmanuel Delahaye wrote:
DevarajA wrote on 03/09/05 :
Is it possible to write a function that, once called, is executed
together with the caller without stopping it? I've seen such functions
in windows programming, using CALLBACK qualifier before the function
name (is it a macro?). Now I would like to know if this could be
possible in standard C, maybe using some tricks. And going a little
ot.. what other non-standard ways to do that do you know?

Callbacks have nothing to do with concurrent ('executed together ')
functions. They are just user functions called by some lower level
function (system, library...) See the standard qsort() function and its
'compare' callback.

If you want concurrent (well, sort of) execution, you want processes or
threads. Theses are beyond the scope of the C-language. Ask a newsgroup
dedicated to your system.


You define a callback function as a user function called by a
lower level function, but the example you give seems to
illustrate the opposite case, that is, one in which a user
function calls a lower level function. qsort always calls
compare, never the other way round. Have I misunderstood?

JS

Nov 15 '05 #3
John Smith wrote on 03/09/05 :
You define a callback function as a user function called by a lower level
function, but the example you give seems to illustrate the opposite case,
I don't think so.
that is, one in which a user function calls a lower level function. qsort
always calls compare, never the other way round. Have I misunderstood?


This is exactly how the compare() function is called : by qsort() which
is a library function.

user code ------|--> qsort() (RTL code)
compare() <---|---

The compare() function belongs to the user's world.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"There are 10 types of people in the world today;
those that understand binary, and those that dont."
Nov 15 '05 #4
Emmanuel Delahaye ha scritto:
John Smith wrote on 03/09/05 :
You define a callback function as a user function called by a lower
level function, but the example you give seems to illustrate the
opposite case,

I don't think so.
that is, one in which a user function calls a lower level function.
qsort always calls compare, never the other way round. Have I
misunderstood?

This is exactly how the compare() function is called : by qsort() which
is a library function.

user code ------|--> qsort() (RTL code)
compare() <---|---


What do you mean by RTL code?

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Nov 15 '05 #5
"DevarajA" <no@spam.com> wrote in message
news:fQ********************@news4.tin.it...
....
What do you mean by RTL code?


Run Time Library.

Alex
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Eric Entressangle | last post by:
Hi all, is there any trouble setting an C++ static class method as callback function for a C program or library ? Thanks
5
by: Pratik | last post by:
what are callback functions? Where we require callback functions? In what scenario we require callback functions?
11
by: ajay.sonawane | last post by:
Hello ther I read somewhere that callback function should be global or static member function. 1: I could use static member functions but how could I access members of class which ar not static....
15
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index...
4
by: Jimmy | last post by:
I need to use Asynchronous Socket functions in a server application and am learning from sources such as the MSDN2 (http://msdn2.microsoft.com/en-us/library/bbx2eya8.aspx). What I observed is that...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
2
by: Evan Burkitt | last post by:
Hi, all. I have a Windows DLL that exports a number of functions. These functions expect to receive a pointer to a callback function and an opaque void* parameter. The callback functions are...
1
by: kikivenkat | last post by:
Hi, I understand the concept of function pointers. I am a little confused with the call back functions. 1.If a function is invoked using a function pointer, then does it mean the function...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.