|
|
Callbacks in C
What are the pros/cons of using Callback mechanism in C? (Design perspective)
What are the scenarios where it can be applied ?
Tuxpal
|
|
0
|
|
|
|
Reply
|
sureshjayaram (3)
|
6/24/2004 11:37:47 AM |
|
In 'comp.lang.c', sureshjayaram@rediffmail.com (Tuxpal) wrote:
> What are the pros/cons of using Callback mechanism in C? (Design
> perspective)
pros : flexibility, reusability, modularity, testability.
cons : the produced code can be harder to read or to debug... specially when
several levels of callbacks are implied.
> What are the scenarios where it can be applied ?
Mainly, software components (flexible libraries). Actually, it covers any
kind of applications... Sky is the limit.
--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
|
|
0
|
|
|
|
Reply
|
emdelYOURBRA (457)
|
6/24/2004 12:43:20 PM
|
|
In <59cd9c4d.0406240337.665ad4c8@posting.google.com> sureshjayaram@rediffmail.com (Tuxpal) writes:
>What are the pros/cons of using Callback mechanism in C? (Design perspective)
It's a design issue, not a language isse.
>What are the scenarios where it can be applied ?
For starters, have a look at the specification of bsearch() and qsort()
from the standard C library.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
|
|
0
|
|
|
|
Reply
|
Dan.Pop (3615)
|
6/24/2004 3:02:12 PM
|
|
"Tuxpal" <sureshjayaram@rediffmail.com> wrote in message
>
> What are the pros/cons of using Callback mechanism in C?
> (Design perspective)
>
> What are the scenarios where it can be applied ?
>
Callbacks are usually used to leave some functionality out of a module, to
be provided by the caller. A standard library example is qsort(). Another
example would be if you implement some sort of database structure, and
require the caller to provide a getkey() function to retrieve the key from
the data.
The advantage is that the functions using callback are much more general.
qsort() for instance can sort any flat array without being recompiled.
One disadvantage is that providing the callback puts quite a burden on the
caller - you have to know exactly what the comparison function provided to
qsort() is expected to return, for example. If you accidentally return
order-dependent results for two items that in fact compare as equal then the
call could strangely fail just before shipping.
Another disadvantage is that it is harder to write a call-tree of a program
that uses function pointers. For short callbacks this isn't too much of a
problem, but if you use them too heavily you can no longer have a structured
program. This can be a difficulty in Windows programming, for example.
|
|
0
|
|
|
|
Reply
|
Malcolm
|
6/26/2004 8:56:23 AM
|
|
|
3 Replies
46 Views
(page loaded in 8.821 seconds)
Similiar Articles: calling member functions from WNPROC callback functions - comp ...{Thopugh this, at first glance is Windows specific which would make it off topic, the actual problem of the call back has more general application -... SWIG CallBack from C++ into Java-Class - comp.lang.java.programmer ...I tried from Java-Example in SWIG:public static void main(String[] args){System.out.println("Adding and calling a normal C++ callback");System.out.pri... How to tell if an exception has currently been thrown and is being ...... to the minizip/zlib code > invoking them, as that code is written in C and is not exception-safe. So I have > a need to catch the exceptions in the read/write callbacks ... Load data/.mat-file in Simulink - comp.soft-sys.matlab> > thanks > C You can do this using a callback: 1) Open your Simulink model 2) Click "File" -> "Model Properties" -3) Select the second tab, called "Callbacks" in ... std::exception::what() - comp.lang.c++.moderatedI have a component for which clients/observers can register callbacks. If a callback throws an exception that is derived from std::exception, I'd lik... Problem with serial and callback BytesAvailableFcn - comp.soft-sys ...Hello, i have a problem with the callback 'ByteAvailable' function of my serial port. Here the code: serial_test.m s=serial('COM1','BaudRa... checkbox tree callback question - comp.soft-sys.matlabHowever, I do not want to trigger a 'selection change' callback when selecting paths ... "John Anderson" <j.c.anderson@sussex.ac.uk> wrote in message <ig20s0$3ma$1@fred ... help with simple polygon tessellation - comp.graphics.api.opengl ...There are some clues in the callback section: ----- It [the begin callback] is followed by any number of vertex callbacks, which supply the vertices in ... GUI for Fortran programs - comp.lang.fortran... would mean that your main program would be written in c++ and all your working functions and subroutines would be called as callbacks. This is usually done with a C ... glut and (Visual)C++ - comp.graphics.api.openglThe callback functions are static C-style functions, but they each get a pointer to the application by a call to a static class member function, then thell that ... The Function Pointer Tutorials - Callbacks - www.newty.deHow to implement callbacks in C and C++. Explanation and examples in both C and C++. Callback (computer programming) - Wikipedia, the free encyclopediaIn computer programming, a callback is a reference to a piece of executable code that is passed as an argument to other code. This allows a lower-level software layer ... 7/13/2012 5:49:57 PM
|
|
|
|
|
|
|
|
|