将GPOINTER_TO_INT 和 GINT_TO_POINTER 转换为普通 CI 得到:
#include <stdio.h>
#include <stdlib.h>
void *fn(void *v)
{
int *i;
i = malloc(sizeof(int));
*i = (int)(long)v;
return i;
}
int main(void)
{
int *i = fn((void *)(long)10);
printf("%d\n", *i);
free(i);
return 0;
}
它是便携式的吗?
为什么演员表long
?
在 GTK 中用于回调,例如:
#define FLAG 10
static void panel_set_handler(GtkWidget *widget, gpointer data)
{
panel_set(GPOINTER_TO_INT(data));
}
g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(panel_set_handler), GINT_TO_POINTER(FLAG));