我见过的最奇怪的错误,又名)*
我正在用 C 语言编写这个很棒的应用程序,至少我认为它很棒,并且与 GObject 完美融合,过了一会儿我开始遇到这个非常非常奇怪的错误。我也相信已经注意到它并不总是出现。然而,这可能只是 IDE 的错误。无论如何...
GCC 显然抱怨:在“*”标记之前预期有“)”;这发生在头文件中。
这是完全相同的头文件。
#pragma once
#include "global.h"
#include "CharcoalApp.h"
GtkListStore *WebsitesListStore;
// that error is reported for this line
void charcoal_websites_list_initialize(CharcoalApp *app);
据我所知,这来自该函数的 CharcoalApp *app
参数。
因为我无法真正理解为什么会发生此错误,所以我将包含 CharcoalApp.h
文件。 global.h
是一个非常简单的头文件,携带了主要的依赖项,主要是GLib、GObject、GThread、GTK+、WebKit等。
CharcoalApp.h
#ifndef __CHARCOAL_APP_H__
#define __CHARCOAL_APP_H__
#include "global.h"
#include "CharcoalDB.h"
#include "CharcoalWindow.h"
#include "CharcoalWebsitesList.h"
G_BEGIN_DECLS
#define CHARCOAL_TYPE_APP (charcoal_app_get_type())
#define CHARCOAL_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHARCOAL_TYPE_APP, CharcoalApp))
#define CHARCOAL_APP_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHARCOAL_TYPE_APP, CharcoalApp const))
#define CHARCOAL_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHARCOAL_TYPE_APP, CharcoalAppClass))
#define CHARCOAL_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHARCOAL_TYPE_APP))
#define CHARCOAL_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHARCOAL_TYPE_APP))
#define CHARCOAL_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHARCOAL_TYPE_APP, CharcoalAppClass))
typedef struct _CharcoalApp CharcoalApp;
typedef struct _CharcoalAppClass CharcoalAppClass;
typedef struct _CharcoalAppPrivate CharcoalAppPrivate;
struct _CharcoalApp {
GObject parent;
CharcoalAppPrivate *priv;
GtkBuilder *ui;
CharcoalDB *db;
// toplevels
GtkWidget *CharcoalWindow;
};
struct _CharcoalAppClass {
GObjectClass parent_class;
};
GType charcoal_app_get_type(void) G_GNUC_CONST;
CharcoalApp *charcoal_app_new(void);
void charcoal_app_quit(CharcoalApp *app);
G_END_DECLS
#endif /* __CHARCOAL_APP_H__ */
感谢您的帮助!
I'm writing this awesome application, at least I think it awesome, in C with the magnificent blend of GObject and after a while I start getting this very, extremely strange error. I also believe to have noticed it not appearing always. However this might just be the IDE's fault. Anyhow...
GCC, apparently, complains: expected ')' before '*' token; this happens in a header file.
This is that very same header file.
#pragma once
#include "global.h"
#include "CharcoalApp.h"
GtkListStore *WebsitesListStore;
// that error is reported for this line
void charcoal_websites_list_initialize(CharcoalApp *app);
As far as I can see, this comes from the CharcoalApp *app
parameter for that function.
Because I cannot really understand why this error is happening, I'll include the CharcoalApp.h
file. global.h
is a very simple header file that carries the main dependencies, mainly GLib, GObject, GThread, GTK+, WebKit and other.
CharcoalApp.h
#ifndef __CHARCOAL_APP_H__
#define __CHARCOAL_APP_H__
#include "global.h"
#include "CharcoalDB.h"
#include "CharcoalWindow.h"
#include "CharcoalWebsitesList.h"
G_BEGIN_DECLS
#define CHARCOAL_TYPE_APP (charcoal_app_get_type())
#define CHARCOAL_APP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHARCOAL_TYPE_APP, CharcoalApp))
#define CHARCOAL_APP_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), CHARCOAL_TYPE_APP, CharcoalApp const))
#define CHARCOAL_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), CHARCOAL_TYPE_APP, CharcoalAppClass))
#define CHARCOAL_IS_APP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), CHARCOAL_TYPE_APP))
#define CHARCOAL_IS_APP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), CHARCOAL_TYPE_APP))
#define CHARCOAL_APP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), CHARCOAL_TYPE_APP, CharcoalAppClass))
typedef struct _CharcoalApp CharcoalApp;
typedef struct _CharcoalAppClass CharcoalAppClass;
typedef struct _CharcoalAppPrivate CharcoalAppPrivate;
struct _CharcoalApp {
GObject parent;
CharcoalAppPrivate *priv;
GtkBuilder *ui;
CharcoalDB *db;
// toplevels
GtkWidget *CharcoalWindow;
};
struct _CharcoalAppClass {
GObjectClass parent_class;
};
GType charcoal_app_get_type(void) G_GNUC_CONST;
CharcoalApp *charcoal_app_new(void);
void charcoal_app_quit(CharcoalApp *app);
G_END_DECLS
#endif /* __CHARCOAL_APP_H__ */
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
CharcoalApp
未在global.h
中声明。假设您在 C 文件中包含CharcoalApp.h
:您应该正确重新排列头文件或使用前向声明(尽管我认为在这种情况下不需要)。
解决办法有很多:
typedef struct _CharcoalApp CharcoalApp;
移至 CharcoalApp.h 中的 `#include "global.h" 之前;#include "global.h"
并按正确的顺序包含它们(最后是 global.h)。CharcoalApp
is not declared inglobal.h
. Suppose you are includingCharcoalApp.h
in your C file:You should rearrange your header files properly or use a forward declaration (although I don't think is needed in this case).
There are many solutions:
typedef struct _CharcoalApp CharcoalApp;
before `#include "global.h" in CharcoalApp.h;#include "global.h"
from CharcoalApp.h and include them in the proper order (global.h last).我不确定这对每个人来说是否都是显而易见的,但我应该补充一点,它抱怨的原因(我认为)是因为它在解析该代码时不明白 CharcoalApp 是一个类型名称(我见过过去多次出现类似的编译时错误)。我认为它将它作为参数名称而不是参数的类型名称来处理,因此它期望参数列表的结尾(或逗号)而不是另一个不带逗号的参数名称。
I'm not sure if it's obvious to everyone, but I should add that the reason it's complaining (I think) is because it doesn't understand that CharcoalApp is a type name at the time that it's parsing that code (I've seen similar compile-time errors many times in the past). I think it is handling it as a parameter name instead of a parameter's type name, so it expects the end of the argument list (or a comma) instead of another parameter name without a comma.
怎么样:
它并不完全漂亮,但是删除其他标头中包含的标头并用前向声明替换它们是我曾经被教导过并且总是尝试做的事情。
它显着减少了我花在编译器上的循环依赖上的时间,并且在更改通常包含的头文件时还可以缩短构建时间。
:D
How about:
Its not exactly pretty, but removing header includes inside other headers and replacing them with forward declarations is something I was taught once and always try to do.
It reduces the amount of time I spend swearing at the compiler over cyclic dependancy significantly, and it also keeps build times down when changing a commonly included header file.
: D
在我看来,
GtkListStore
没有定义。Looks to me like
GtkListStore
is not defined.尝试将代码更改为:
当您说出 typedef 时,底层结构类型尚未定义,这可能会混淆一些内容。
我通常只是写这样的东西:
Try changing your code to:
When you uttered the typedef, the underlying structure type wasn't defined yet, and this MIGHT have confused something.
I normally just write something like: