1

In specific I am working in linux environment. This is an opengl application. Upon a calculation of certain geometries, I want to be able to fire an event whenever a new geometry is created. Is there any .NET equivalent of events in C ??

Thanks, Vishnu

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
Vishnu Pedireddi
  • 2,142
  • 4
  • 25
  • 34

4 Answers4

0

Events in C are implemented using function callbacks. The linked question has a couple answers that address how to code callbacks.

Community
  • 1
  • 1
Cogwheel
  • 22,781
  • 4
  • 49
  • 67
  • I have native C application in linux environement. More specifically, this is an OpenGL application. On the creation of certain input geometries, i want to be able to call an event, instead of calling a function explicitly. Is there anything analogous to events in .NET ?? – Vishnu Pedireddi Jul 22 '10 at 18:19
  • 1
    @de costo - Please put that information in your actual question. – J. Polfer Jul 22 '10 at 18:21
  • I added a link to my post. The answers in that other question describe using function pointers for callbacks (the 2nd answer is particularly relevant). – Cogwheel Jul 22 '10 at 18:21
0

With gnome libraries or gtk+ (which is built on top of it)? You can do it all yourself with function pointers, but this is the only "standard" C library that I've personally used that standardized events and callbacks. There's probably others out there, too.

eruciform
  • 7,680
  • 1
  • 35
  • 47
0

To translate from .NET land:

An "event" is simply the calling of a function. To make this configurable, you need to give the thing that generates the "event" a function pointer. The function pointer is called, and is the thing that is "done" when the "event" occurs.

A thing to "do" is a function in C and C++.

If you only want to "do" one thing upon an "event". You'd pass in a pointer to your function, which is the thing you want to "do" upon your "event" as a function pointer to the thing that causes the "event." This is called a callback. Other posts have lots of examples on how this works.

If you need to "do" multiple things on an "event", you'll need to use a signal/slot implementation like boost::signal. Or if OpenGL has something similar, I'd use that. In that case, you have multiple callbacks.

J. Polfer
  • 12,251
  • 10
  • 54
  • 83
0

Though I can't say I'd really recommend using them, a possible alternative to callbacks would be signals.

You can use signal to say how a particular signal should be handled, and raise to send a particular signal. Note, however, that there are serious restrictions on what you can do in a signal handler. Lots of code isn't really written to deal well with signals, and quite a bit of it assumes that almost any signal implies such a serious problem that continued execution after a signal may be problematic.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111