While practicing a tutorial on GTK+ I have encountered sample code that looks like this:
gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
all of the authors code has a space between function and (), but so does the typecasts.
obviously gtk_misc_set_alignment() is a function, but how do I tell if
GTK_MISC (label) is a function or a typecast?
Sorry for the noob question, I am a noob programmer,
Thanks in advance
Actually,
GTK_MISCis a macro that hides a "classic" C typecast. It’s probably something like:You could instead simply write:
I don’t know exactly why GTK provides such macros, maybe they like to "emulate" the "function-like" cast that C++ provides.
Edit
Ok, maybe I got it. I didn’t find a specific documentation for
GTK_MISC, but it seems to be exactly the same thing asG_OBJECT, which says:So, probably
GTK_MISCtoo performs some runtime checks on the pointer to check if it can be actually casted to aGtkMisk *. You could say that it is somewhat the concept ofdynamic_castin C++.