Re: Macro vs function was: Method to query toggle button state?
- From: Lars Hallberg <lah micropp se>
- To: chak is tsukuba ac jp, gtk-list redhat com, mayfield sackheads org
- Subject: Re: Macro vs function was: Method to query toggle button state?
- Date: Tue, 23 Feb 1999 00:53:22 +0100
On Sat, Feb 20, 1999 at 10:42:26AM +0100, Manuel M. T. Chakravarty wrote:
>
> Actually, even a macro has its disadvantages. Writing a
> GTK+ binding for a high-level language (one where C structs
> cannot be accessed directly, but C functions can be called
> via a foreign function interface), the lack of query
> functions is rather annoying. I myself was wondering
> whether they are omitted by purpose or just because nobody
> bothered to implement them. In case of the latter, I would
> be willing to supply patches.
>
I am writing a C++ wrapper for glib and actully wish for MORE macros.
Hovever macros have sideefects so they shuld not be alowed to slip
in by suprise. I have the folowing sugestion.
For every function, foo, apropriate to be a macro, following is done:
In header file:
#define G_MACRO_foo(x) do-foo-stuff
void g_foo(x);
In C file:
void g_foo(x)
{
G_MACRO_foo(x);
}
In this way:
* C programmer will newer be suprised by that a function is a macro.
* Other language have always a real funktion to call.
* C programmer can acces the macro when needed for speed.
* It posable to use the macro to build an inline C++ funktion for
effishent C++ interface.
The alterativ for a C++ wrapper if no macro is avalible is to:
* Use the function. It is anoying to know one culd easy make it
better (if a library can easy make it better it shuld do so).
* Duplikate the library C code in the C++ interface and ever after
be forced to stay in synk manuely (noooo fun)...
The only tradeof I can see is that it is slighly, but only
slighly, tidius to write first time. When all the rest in
GpLib is done I can do the work but I have to know if it
is seen as acceptable practice.
BTW
The glib C++ wrapper is updated. The 'classprotokoll' have changed and
dynamic pointer templates is added. Still want to know if I do step
on anyones toes, especily if I clach with or duplikate stuf made in
GTK--
URL: http://www.micropp.se/gplib/
Thanks /Lars
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]