Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Setting Enum integer constants #39

Dohle opened this Issue · 5 comments

4 participants



In order to be able to use another f03 compiler two changes to the cfwrapper script were necessary. The boz constants were not accepted as scalar-int-constant-expr in the enumerator definition and assignment.

Instead of converting to a bit pattern the same C like bit shifting can be used:

        def set_bit_field(match):
          """ Returns the Fortran bitfield from a C enum flag"""
          b = int(
          field = "1"
          s = "ISHFTC(1,"+str(b)+")"
          return s

And for the hex constants simply insert the INT intrinsic function:

        # Is it in hexadecimal ?
        parameters[0] = re.sub("0x([0-9A-Fa-f]+)", "INT(z'\\1')", parameters[0])

Now a major f03 compiler accepts the statements in gtk.f90/gtkenums-auto.f90. For example:

enum, bind(c) !GModuleFlags
enumerator :: G_MODULE_BIND_LAZY = ISHFTC(1,0)
enumerator :: G_MODULE_BIND_LOCAL = ISHFTC(1,1)
enumerator :: G_MODULE_BIND_MASK = INT(z'03')
end enum



Thank you Henk,
I will test and and apply your patch as soon as I have some time to spend on gtk-fortran.
But which "major f03 compiler" do you use ? (I could put its name on the wiki)


I have included your patches in


Just a few random thoughts that may or may not be useful.

There are some examples of the use of g_object_get_data and g_object_set_data in the high-level list and tree routines in gtk-hl-tree.f90 which might give some feel for how the C stuff maps into Fortran.

The iso_c_binding module in gfortran 4.4.x and 4.5.x is terminally broken, in particular c_funloc does not work, therefore I would strongly advise not to use those versions for anything involving c-bindings not just gtk-fortran, the problem is solved in gfortran 4.6 and 4.7 .

@vmagnin vmagnin closed this

Dear Henk,

It seems you were trying to use f03gl with gtk-fortran. Do you have a simple working example now? I would like to do this..

Thank you.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.