ANSI C编译错误:','标记之前的预期表达式

时间:2012-12-12 01:29:54

标签: c compiler-errors c89

在尝试编译我编写的一些代码时,我继续收到此错误,文件中的位置完全没有用。这使用gtk 2.0。

以下是我在编译时收到的内容:

  

charles @draton-generico:〜/ Documents / C89 $ gcc -x c -ansi -g bahbahbah.c -o bahbahbah pkg-config --cflags --libs gtk+-2.0

     

bahbahbah.c:在函数'main'中:

     

bahbahbah.c:28:1:错误:','令牌

之前的预期表达

以下是我要编译的代码:

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

void closure(void)
{
    gtk_main_quit();
    printf("gtk_main_quit() has been called.\n");
}

void main(int argc, char* argv[])
{
    gboolean check = gtk_init_check(&argc, &argv);
    if (check == FALSE)
    {
        printf("Failed to initialize toolkit.\nTerminating.\n");
        exit(EXIT_FAILURE);
    }
    else
    {
        printf("Initialized toolkit.\n");
        GtkWidget* main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title((GtkWindow*)main_window, "BLAH");
        gtk_window_set_default_size((GtkWindow*)main_window, 700, 700);
        g_signal_connect(main_window, "delete-event", closure, void);
        gtk_widget_show(main_window);
        printf("Window created, sleeping in gtk_main().\n");
        gtk_main();
    }       
    printf("Exiting.\n");
    exit(EXIT_SUCCESS);
}

请帮忙。 :(

2 个答案:

答案 0 :(得分:5)

在第28行使用NULL替换void

g_signal_connect(main_window, "delete-event", closure, NULL);

答案 1 :(得分:0)

voidKey-word! 有g_signal_connect()

的描述
#define             g_signal_connect(instance, detailed_signal, c_handler, data)

Connects a GCallback function to a signal for a particular object.

The handler will be called before the default handler of the signal.

instance :
    the instance to connect to.

detailed_signal :
    a string of the form "signal-name::detail".

c_handler :
    the GCallback to connect.

data :
    data to pass to c_handler calls.

Returns :
    the handler id

所以,你只想要传递给这个功能?然后你应该使用NULL