I want to store the exVars in a global array for easy access.
Creating a global GtkWidget exArray[len] variable and added each of them inside resulted in the following error message when attempting to compile for each element in the variable.
main.c:84:2: warning: initialization of âGTypeClass *â {aka âstruct _GTypeClass *â} from incompatible pointer type âGtkWidget *â {aka âstruct _GtkWidget *â} [-Wincompatible-pointer-types]
84 | button0,
| ^~~~~~~
main.c:84:2: note: (near initialization for âbuttons[0].parent_instance.g_type_instance.g_classâ)
main.c:84:2: error: initializer element is not constant
main.c:84:2: note: (near initialization for âbuttons[0].parent_instance.g_type_instance.g_classâ)
main.c:85:2: warning: initialization of âunsigned intâ from âGtkWidget *â {aka âstruct _GtkWidget *â} makes integer from pointer without a cast [-Wint-conversion]
What is the correct way to create and store GtkWidget variables in an array?
That sounds like a bad idea. I mean, if thereâs multiple different widgets, then they surely have different use so they should be stored in a struct separately with identifying names, such as âincrement_buttonâ or âmessage_labelâ.
If you use an array then youâll likely not want to hardcode the indexes to e.g. 2 or 0, so youâll start using an enumeration to index it. Except it would just end up being a reimplementation of structs in a less straightforward way.
Anyway, without your full code (including your array declaration) itâs gonna be difficult to help much here with regards to the error message.
If you mean a global variable which is an array, then thatâs not a very good idea because it means you wonât be able to have multiples instances of your custom widget. The normal way of doing this is subclassing the widget, where youâll be able to store it in your widgetâs private struct.
At the end of the day, if you really need to store them in a variable then