Re: Some question about GLib

Le 25/07/2014 23:46, Ameen Sayegh a écrit :
[...] and I'm interested in C Language and its simplicity

I'm afraid that's not completely true :)


I have some question about the source code that I don't know what it
does mean for example:
gmem.h:120: "(void) (0 ? (gpointer) *(pp) : 0);"

That's a hack to catch misuses of the g_clear_pointer() macro.  See

The idea is that if pp is a pointer and not a pointer to pointer, each
branch of the conditional expression will have a different type and this
is invalid -- hence the compiler will error-out.

To take Xavier's example, imagine the following code:

        struct { gpointer x; } test;

The first static assertion in g_clear_pointer() (which is (sizeof *(pp)
== sizeof (gpointer))) won't catch it as the struct has the size of a
gpointer, so it would go unnoticed.  Therefore, there is this second
hack to make sure to catch this.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]