[PD] t_scalar member sc_vec
Miller Puckette
msp at ucsd.edu
Fri Feb 21 04:05:09 CET 2014
Hi all -
I don't know if this is a reasonable thing to do in 2014 - it's a coding trope
I learned around 1981. As far as I know C has no clean way to describe a
packed data structure with a header and then a variable number of identical
elements (like a soundfile with a header followed by samples). In this case,
the object consists of a structure,
t_gobj sc_gobj;
t_symbol *sc_template;
followed in memory by an array of t_words. One can't make a zero-size arary
in standard C (as far as I know) and so it's declared as having the artificial
size 1. If there are n elements, the size of the structure is
sizeof(t_scalar) + (n-1) * sizeof(t_word)
subtracting 1 for the one that stood in for the array.
cheers
Miller
On Thu, Feb 20, 2014 at 06:32:48PM -0800, Jonathan Wilkes wrote:
> Can anyone explain what's going on with this in m_pd.h:
>
> typedef struct _scalar /* a graphical object holding data */
> {
> t_gobj sc_gobj; /* header for graphical object */
> t_symbol *sc_template; /* template name (LATER replace with pointer) */
> t_word sc_vec[1]; /* indeterminate-length array of words */
> } t_scalar;
>
> How is a static t_word array of size 1 an indeterminate-length array? Is its placement as the last member of the struct required?
>
> I see lots of mysterious casts in the internals of Pd's data structures. What's the trick here, and is it documented anywhere on the interwebs, a C standard doc, etc.?
>
> Thanks,
> Jonathan
> _______________________________________________
> Pd-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
More information about the Pd-list
mailing list