tags:

views:

222

answers:

5

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!

A: 

Looks to me like GtkListStore is not defined.

Hogan
It is. It's a GTK+ type. GTK+ is included in global.h
act1v8
A: 

Try changing your code to:

struct _CharcoalApp { 
  GObject parent; 

  CharcoalAppPrivate *priv; 

  GtkBuilder *ui; 
  CharcoalDB *db; 

  // toplevels 
  GtkWidget *CharcoalWindow; 
}; 

struct _CharcoalAppClass { 
  GObjectClass parent_class; 
};

typedef struct _CharcoalApp         CharcoalApp;
typedef struct _CharcoalAppClass    CharcoalAppClass; 
typedef struct _CharcoalAppPrivate  CharcoalAppPrivate; 

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:

typedef struct { 
  GObject parent; 

  CharcoalAppPrivate *priv; 

  GtkBuilder *ui; 
  CharcoalDB *db; 

  // toplevels 
  GtkWidget *CharcoalWindow; 
} CharcoalApp; 
John R. Strohm
Doesn't help. :( Still the same error.
act1v8
+1  A: 

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.

BlueMonkMN
That is very true. I removed the "*app" part and it reports errors like "parameter names (without types) in function declaration".
act1v8
+2  A: 

CharcoalApp is not declared in global.h. Suppose you are including CharcoalApp.h in your C file:

  1. CharcoalApp.h is read up to #include "global.h"
  2. global.h is included
  3. Error: expected ')' before '*' token

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:

  1. the proper way: include CharcoalApp.h from global.h, not the reverse;
  2. move typedef struct _CharcoalApp CharcoalApp; before `#include "global.h" in CharcoalApp.h;
  3. remove #include "global.h" from CharcoalApp.h and include them in the proper order (global.h last).
ntd
I tried rearranging the header files, nothing. The main problem, tho, is in the CharcoalWebsiteList.h file: in the C counterpart of that file only CharcoalWebsiteList.h is being included.
act1v8
+1  A: 

How about:

#pragma once
#include "global.h"

//#include "CharcoalApp.h"
struct CharcoalApp;

GtkListStore *WebsitesListStore;

// that error is reported for this line
void charcoal_websites_list_initialize(CharcoalApp *app); 

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

Danny Parker
struct CharcoalApp* is not the same as CharcoalApp*, unless it's been told to typedef them. And if it had been told to typedef them, then this problem wouldn't be happening ... ;)
Pod