gboolean

Paolo Redaelli <[email protected]> Thu, 28 Dec 2006 16:29:10 +0100
Newsgroups gmane.comp.lang.eiffel.smalleiffel
Message-ID <[email protected]>
GTK, Glib and almost any other C library that I know mimic boolean 
values with integers, with 0 as False and 1 or anything else as True.

I was wondering which is the "best" wrapping strategy:
Let's have "gboolean gtk_statusbar_get_has_resize_grip (GtkStatusBar 
*statusbar);"
I usually wrap it this way:

=======================
feature {} -- External call
    gtk_statusbar_get_has_resize_grip (a_statusbar: POINTER): INTEGER is
        external "C use <gtk/gtk.h>"
        end
    gtk_statusbar_set_has_resize_grip (a_statusbar: POINTER; a_setting: 
INTEGER) is
        external "C use <gtk/gtk.h>"
        end

feature -- query  
    has_resize_grip: BOOLEAN is
        do
            Result := gtk_statusbar_get_has_resize_grip(handle).to_boolean
        end
    set_has_resize_grip (a_setting: BOOLEAN) is
        do
            gtk_status_bar_set_has_resize_grip(handle, a_setting.to_integer)
        end           
=================================================

This approach, the "correct" one implies many conversions from integers 
to boolean and back. While those should be easily optimized away by both 
SmartEiffel and the C compiler (usually gcc), I was wondering if relying 
more or less explicitly on the C cast would be more 
appropriate/faster/easier .....

feature {} -- External call
    gtk_statusbar_get_has_resize_grip (a_statusbar: POINTER): BOOLEAN is
        external "C use <gtk/gtk.h>"
        end
    gtk_statusbar_set_has_resize_grip (a_statusbar: POINTER; a_setting: 
BOOLEAN) is
        external "C use <gtk/gtk.h>"
        end

feature -- query  
    has_resize_grip: BOOLEAN is
        do
            Result := gtk_statusbar_get_has_resize_grip(handle)
        end
    set_has_resize_grip (a_setting: BOOLEAN) is
        do
            gtk_status_bar_set_has_resize_grip(handle, a_setting)
        end           

I know it seems almost trivial... is it really?
Is the implicit C cast from int to char dangerous? I think not.
Thanks in advance for your attention and

    HAPPY GNU YEAR!
        Paolo

PS: I posted it on both mailing lists. Wrappers developers, please 
answer on the SE mailing list or - if you aren't subscriber - asnwer to me.