Discards ‘volatile’ qualifier warning in Vala

This should include gobject-2.0 as below.

$ gcc $(pkg-config --cflags gobject-2.0) example.c example.catalog.c $(pkg-config --libs gobject-2.0)

The discards 'volatile' qualifier is from g_once_init_enter() in line 148 below.

   144  GType
   145  example_catalog_get_type (void)
   146  {
   147          static volatile gsize example_catalog_type_id__once = 0;
   148          if (g_once_init_enter (&example_catalog_type_id__once)) {
   149                  GType example_catalog_type_id;
   150                  example_catalog_type_id = example_catalog_get_type_once ();
   151                  g_once_init_leave (&example_catalog_type_id__once, example_catalog_type_id);
   152          }
   153          return example_catalog_type_id__once;
   154  }
   155  

This is due to the fact that g_once_init_enter() was a function in the past and used to take a volatile location argument. The volatile qualifier currently is only a historical artifact and should not be used as mentioned in the docs. For more details you can refer:

$ git log --grep=volatile glib/gthread.c

So, changing

   147          static volatile gsize example_catalog_type_id__once = 0;

to

   147          static gsize example_catalog_type_id__once = 0;

in C code should remove the warning, but it’s up to the vala codegen.

So, it should be safe to ignore the warning.

2 Likes