[PD] free C lesson

Claude Heiland-Allen claude at mathr.co.uk
Mon Aug 17 16:55:00 CEST 2015


On 17/08/15 15:36, Jonathan Wilkes via Pd-list wrote:
> Hi list,Wondering if someone will give me a free lesson in C programming.
> In g_traversal.c, there's some code to retrieve a float from a t_word* vec.  It looks like this:
> *(t_float *)(((char *)vec) + onset));
> Why does vec need to be cast to char*?  t_word has to be as big as the largest member of the union, and the largest member has to be the same size as char*, right?  (Otherwise we'd have big problems...)

aiui pointer arithmetic is in increments of sizeof(pointee)
if onset is measured in bytes (I don't know if it is in this case, but 
it looks likely), then you need to have a pointer to bytes for the 
addition to be meaningful.  vec is already a pointer, but adding onset 
to a t_word* would offset the address by onset*sizeof(t_word) bytes




More information about the Pd-list mailing list