Forgive me if every other C programmer reading this thinks I'm an imbecile for not picking up on this before. Whilst reading through some GTK documentation (I may have a GTK category on this blog in the future), I noted that
- In a C structure, the first element is always offset 0 bytes from the start of the structure
Fair enough. Now, GTK uses something called GObjects. I was reading about inheritance in GObjects and it kept saying you just cast a GObject pointer to it's parent struct type to get the parent elements. I was thinking hang on, don't they mean dereference? but of course no! GObjects always put their parent class structure as the first element. Due to this 0-byte offset thing, the two are equivalent (but I presume the cast is cheaper).