How does the declared function C have no implementation?

What puzzles me is the lack of implementation code for the glade_project_get_type function in the following code snippets.

From the .c file:

project = g_object_new (GLADE_TYPE_PROJECT, NULL);

From the linked header file:

#define GLADE_TYPE_PROJECT   (glade_project_get_type ())

This seems to be an ad glade_project_get_type():

GType  glade_project_get_type (void) G_GNUC_CONST;

/* From glib/gmacros.h:
    #define G_GNUC_CONST    __attribute__((__const__))

    __attribute__((const)) function attribute
 Many functions examine only the arguments passed to them and have no effects 
 except for the return value. 
 If a function is known to operate only on its arguments then it can be subject
 to common sub-expression elimination and loop optimizations.
*/ 

I cannot find the implementation code for glade_project_get_type () anywhere, but the software compiles without errors, so obviously there is something that I don’t understand.

I expected that there would be something like:

GType  glade_project_get_type (void)
{
  GType aType;

  < some code giving a value to aType >
  return aType
}

So what I do not understand about programming in C?

+4
source share
2 answers

The code that implements glade_project_get_typeis in the library libgladeui, which is compiled separately and associated with the executable file glade.

libgladeui glade. glade_project_get_type glade-project.c. glade_project_get_type , , glade_project_get_type:

G_DEFINE_TYPE_WITH_CODE (GladeProject, glade_project, G_TYPE_OBJECT,
                         G_ADD_PRIVATE (GladeProject)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
                                                glade_project_model_iface_init)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
                                                glade_project_drag_source_init))

glib, gobject/gtype.h. - , ( ##) ( glade_project) , , _get_type.

, :

#define MAKE_FUNC(name, val) int my_ ## name ## _function (void) { return val; }

MAKE_FUNC(magic, 42)

int main(void) {
  printf("%d\n", my_magic_function());
  return 0;
}

my_magic_function, MAKE_FUNC . MAKE_FUNC(magic, 42)

int my_magic_function(void) { return 42; }
+4

glade_project_get_type() , . libglade. , , .

, , . C, . , , . , , , , . libglade .

+2

All Articles