Re: Gtk object system



	At least we use plain C for gtk code. With this in mind you can
understand virtual functions as simple function pointers embedded into a
structure:

	struct class_A
	{
		void (*virtual_function)( int abc );
	};

So if you have an object of class_A you can of course call its method:

	class_A		obj_a;

	obj_a.virtual_function( 5 );

Since we have no "this" pointer in plain C we often have to put it on the
stack:
pointer_to_some_object->virtual_function(pointer_to_some_object,...);

All of that are nothing more than simple function calls. Using the signal
system has some advantages over direct function calls:
	1. You can easily hook on signals and extend some functionality
		without changing internal code.
	2. You can write functions without exporting their prototypes.
	3. You can easily exchange functions at runtime, so the user can
		configure what he gets from a button press, for example.
	4. The application framework has more control over signal
		functions so it can hook even on critical errors like
		floating point exceptions and segmentation faults, without
		killing the whole application.
The one and only disadvantage is a small overhead in calling signals.

	The programming language C would not live anymore without
techniques like signals, because they extend the language by features
known from interpreted languages, where you can change the code executed
at runtime.

	GTK is not only a GUI framework but shadows Operating System
features too. So it can work as a general application programmers
interface (API) abstracting the work which has to be done for several
operating systems at once ( Linux, Unix, Win32, MacOS ).

CU INGO




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]