[Dynamite] ANSI C question
Ian Holmes
ihh@fruitfly.org
Thu, 23 Mar 2000 13:17:47 -0800 (PST)
On Thu, 23 Mar 2000, Guy Slater wrote:
> > > Do either of you know if this is strict ANSI, i.e. can we be sure that the
> > > first two fields of _GArray (data & len) are mapped to the same memory
> > > locations as data and len in _GRealArray in all C compilers?
> >
> > This is strict ANSI interestingly. (read the back of K&R about struct
> > layout).
>
> Given that:
>
> o The first member must always have offset zero
> o Other members have increasing offset
> o Structure padding is implementation defined
>
> It still isn't clear to me (from K&R) whether the padding
> has to be *consistent* throughout the implemenataion.
hmmmm
>
> Anyway, I doubt the glib people wouldn't have used it if
> it wasn't safe - they seem to have gone to a lot of effort
> to ensure portability.
maybe we want to be even more portable than GLib though...
>
> > > If so it makes life a lot easier...
>
> Saves much messing with offsetof() or somesuch ..
We *could* do inheritance this way as Ewan says GTK does.
We would have to decide fairly soon whether we wanted to do inheritance
this way or by the "derived interface has a pointer to base interface"
model that was in the code I posted the other day.
The GTK model is:
* slightly more efficient
* much less safe
I can't help feeling that we are seriously retreading ground here. Oh
well.
Ian