g_slice_new 不接受我的结构类型
这就是我构建它的方式: gcc pkg-config --cflags --libs gtk+-2.0
-ospawnspawn_with_pipes.c
在下面的示例片段中,我收到错误:“Data”之前的语法错误- 它引用 data= g_slice_new(Data);
#include <gtk/gtk.h>
typedef struct
{
/* Buffers that will display output */
GtkTextBuffer *out;
GtkTextBuffer *err;
/* Progress bar that will be updated */
GtkProgressBar *progress;
/* Timeout source id */
gint timeout_id;
}Data;
data= g_slice_new(Data); //error here
that is how I build it: gcc pkg-config --cflags --libs gtk+-2.0
-o spawn spawn_with_pipes.c
In the snippet of example below, I get an error: syntax error before "Data - it refers to data= g_slice_new(Data);
#include <gtk/gtk.h>
typedef struct
{
/* Buffers that will display output */
GtkTextBuffer *out;
GtkTextBuffer *err;
/* Progress bar that will be updated */
GtkProgressBar *progress;
/* Timeout source id */
gint timeout_id;
}Data;
data= g_slice_new(Data); //error here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
函数外部的初始化器必须是常量表达式。 您不能调用其中的函数。
另外,代码中的变量“data”是一个int,g_slice_new的返回是一个gpointer。
您将需要更改“数据”的定义并将初始化移至 main 中:
Initalisers outside of a function must be constant expressions. You can't call a function within them.
In addition, the variable "data" in your code is an int and the return of g_slice_new is a gpointer.
You will need to change the definition of "data" and move the initialisation into main: