g_slice_new 不接受我的结构类型

发布于 2024-07-29 03:24:42 字数 498 浏览 7 评论 0原文

这就是我构建它的方式: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹉夏雨初晴づ 2024-08-05 03:24:42

函数外部的初始化器必须是常量表达式。 您不能调用其中的函数。

另外,代码中的变量“data”是一个int,g_slice_new的返回是一个gpointer。

您将需要更改“数据”的定义并将初始化移至 main 中:

gpointer data;

int main(int argc, char *argv[])
{
    ...
    data = g_slice_new(Data);

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:

gpointer data;

int main(int argc, char *argv[])
{
    ...
    data = g_slice_new(Data);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文