I use the following function to make automatic notifications for user:
#define LOG(...) logger((sizeof((int32_t[]){0, ## __VA_ARGS__})/sizeof(int32_t)-1), __VA_ARGS__)
..................
void informer(int32_t count, ...)
{
GtkTreeModel *model = 0;
GtkTreeIter iter;
model = gtk_tree_view_get_model(GUI.log_view);
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
char log_body[16384] = {0};
/* Add current time */
GDateTime *now;
char *time;
now = g_date_time_new_now_local ();
time = g_date_time_format (now, "%c");
g_date_time_unref (now);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, LOG_TIME, time, -1);
free(time);
/* Parse input data*/
va_list ap;
va_start(ap, count);
while (count--) {
if(!count)
{
enum error_type type = va_arg(ap, int);
if(type == OK)
{
gtk_list_store_set(GTK_LIST_STORE(model), &iter, LOG_TYPE, "OK", -1);
}
.............................................
else
{
gtk_list_store_set(GTK_LIST_STORE(model), &iter, LOG_TYPE, "Неизв.", -1);
}
break;
}
char* arg = va_arg(ap, char*);
strcat(log_body," ");
strcat(log_body,arg);
}
va_end(ap);
gtk_list_store_set(GTK_LIST_STORE(model), &iter, LOG_BODY, log_body, -1);
}
So in such a call
LOG("Unknown error", "Error!", ERROR);
where ERROR is enum, gcc show warning during compilation:
warning: (near initialization for ‘(anonymous)[1]’)
warning: initialization makes integer from pointer without a cast [enabled by default]
warning: (near initialization for ‘(anonymous)[2]’)
warning: initialization makes integer from pointer without a cast [enabled by default]
warning: (near initialization for ‘(anonymous)[3]’)
warning: initialization makes integer from pointer without a cast [enabled by default]
The code work perfectly, but is this safe in real?
If it is, how to get rid of it? I tried to use #pragma GCC diagnostic error "-Wpointer-to-int-cast"
with corresponding push and pop but with no effect.