[Gtk-sharp-list] Cross Platform Assemblies?

Charles Iliya Krempeaux charles@reptile.ca
15 Mar 2003 23:53:53 -0800


Hello,

Looking at GLib's "gtypes.h", I see definitions like:

    typedef char   gchar;
    typedef short  gshort;
    typedef long   glong;
    typedef int    gint;
    typedef gint   gboolean;

    typedef unsigned char   guchar;
    typedef unsigned short  gushort;
    typedef unsigned long   gulong;
    typedef unsigned int    guint;

    typedef float   gfloat;
    typedef double  gdouble;

Now, what this means is that something like a "gint" is going to be a 
different size on different platforms.  (On a x86 architecture it will
be 32 bits wide.  On something else it may be 64 bits wide.)

Now, in the Gtk# code, we have DllImport statements all over the
place that make assumptions about the size of these things.
For instance, we have the C declaration:

    void gtk_widget_set_size_request (GtkWidget *widget,
                                      gint       width,
                                      gint       height);


And in the Gtk#, this gets turned into:

                [DllImport("libgtk-win32-2.0-0.dll")]
                static extern
                void gtk_widget_set_size_request(IntPtr raw,
                                                 int width,
                                                 int height);

Now, this says that a C# "int" is the same as a C "gint".

Now, on a 32 bit architecture this is true.  But, on a 64 bit
architecture, this isn't!!!

This is because, on a 64 bit architecture, a C "gint" will be
64 bits wide.  But the .NET "int" will still be 32 bits wide
(since it is an alias for "System.Int32".)

Thus we seem to have a problem.

This will likely require us to build 32 bit versions, 64 bit versions,
and possible other size versions, of all our assemblies.  (And maybe
create stub .dll's that link to the correct one at runtime.)


See ya

-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/