On 10/3/2011 10:08 AM, Mike Manilone wrote:
> Hi there,
>
> I often write app with GObject.
>
> Well, of course, GObject is hard to use.
Makes one wonder why you "often" choose to torture yourself ...
> So I thought about making a set of macros to make this job easier.
>
> Just like this (assume the class is 'GtkButton'):
> #define NAME GTK
> #define SPACE BUTTON
> #define Type GtkButton
> #define name_space gtk_button
>
> static void
> name_space ## _init (Type *self)
Um, er, no. The ## operator is only defined within a macro
replacement list, not in "open code."
> {
> /* do something */
> }
>
> Well, GObject always needs some macros to do something usual.
Sorry; I don't understand this.
> So can I
> write these macros like this?
> #define NAME##_IS_##SPACE ...
> #define NAME##_IS_##SPACE##CLASS ...
No; same reason: You're using ## outside a macro expansion.
> Maybe I need a try. But my laptop is broken these days.
> So, could someone please tell me what happens?
Nothing good.

I'm not familiar with GObject, but I get the
sense that you're not so much using it as fighting it. Perhaps it
would be helpful to read code written by GObject experts; this is
often a good way to pick up a framework's idioms and best practices.
--
Eric Sosman
d