Start gboolean with the value

Hello everyone
How to start a gboolean with the value FALSE.

gboolean foo = FALSE;

Like that.

1 Like

This Error:
error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘attribute’ before ‘=’ token
32 | gboolean foo = FALSE;

It does not work:

   struct _FncBoxRowView{
            GtkListBoxRow           parent;
            /* The Widgets */
            GtkLabel                *label_icon;
            GtkLabel                *label_name;
            GtkRevealer				*revealer;
            GtkCheckButton	*check_button;
            gint	id_row;
    	gint	id_fk;
    	gboolean is_check  = FALSE;

This Works:

static void
fnc_box_row_view_init (FncBoxRowView *self)
        gtk_widget_init_template (GTK_WIDGET (self));
        self->is_check = FALSE;

why not?

You can’t initialise structure members inside their definition. I mean: it’s how C works. You may want to read a book about it. Or you may not want to use C at all, if you don’t know it.

In any case, your question has nothing to do with GNOME or GTK.

As a side note, though, every instance of a GObject will be filled with zeros when it’s allocated, so you don’t need to set fields to 0, NULL, or FALSE values.

1 Like

Thanks for the guidance.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.