<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1439828948109_27085" dir="ltr">Ah, ok-- I forgot my pointer arithmetic rules.<br></div><div id="yui_3_16_0_1_1439828948109_31145" dir="ltr">Once I remembered how it works, I still wasn't understanding how you could be doing pointer arithmetic with byte granularity when t_word is wider than 1 byte.  But then I see from template_find_field you are multiplying the onset by sizeof(t_word).</div><div id="yui_3_16_0_1_1439828948109_33189" dir="ltr"><br></div><div id="yui_3_16_0_1_1439828948109_33190" dir="ltr">So now, further down the rabbit hole of knowledge, I'm wondering why you multiply by sizeof(t_word) at all.  If you didn't, couldn't the (char *) cast go away?<br></div><div id="yui_3_16_0_1_1439828948109_34556" dir="ltr"><br></div><div id="yui_3_16_0_1_1439828948109_34555" dir="ltr">-Jonathan<br></div><div id="yui_3_16_0_1_1439828948109_27086"><span></span></div>  <br><div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"> <font face="Arial" size="2"> On Monday, August 17, 2015 12:24 PM, Miller Puckette <msp@ucsd.edu> wrote:<br> </font> </div>  <br><br> <div class="y_msg_container">I don't thing the width of (char *) enters into it (it's a pointer, 8 chars in <br clear="none">64 bit addr space)  - the direct contrast to be made is (char) vs (t_word).<br clear="none"><br clear="none">Not sure if that answers the question though...<br clear="none"><br clear="none">cheers<br clear="none">M<br clear="none"><div class="yqt3808572402" id="yqtfd63956"><br clear="none">On Mon, Aug 17, 2015 at 03:52:27PM +0000, Jonathan Wilkes via Pd-list wrote:<br clear="none">> Thanks, I think I'm getting it.<br clear="none">> So is char* guaranteed to be the same width as sizeof(t_word)?  If so, are you just using it as a shorthand?<br clear="none">> <br clear="none">> Thanks,<br clear="none">> Jonathan<br clear="none">> <br clear="none">> <br clear="none">>  <br clear="none">> <br clear="none">> <br clear="none">>      On Monday, August 17, 2015 11:31 AM, Miller Puckette <<a shape="rect" ymailto="mailto:msp@ucsd.edu" href="mailto:msp@ucsd.edu">msp@ucsd.edu</a>> wrote:<br clear="none">>    <br clear="none">> <br clear="none">>  Here's an example...<br clear="none">> <br clear="none">> #include <stdio.h><br clear="none">> <br clear="none">> float foo[2];<br clear="none">> <br clear="none">> main()<br clear="none">> {<br clear="none">>     printf("foo = %p\n", foo); <br clear="none">>     printf("incremented as float: %p\n", foo+1);<br clear="none">>     printf("incremented as (char *): %p\n", ((char *)foo)+1);<br clear="none">> }<br clear="none">> <br clear="none">> ---><br clear="none">> <br clear="none">> foo = 0x601038<br clear="none">> incremented as float: 0x60103c<br clear="none">> incremented as (char *): 0x601039<br clear="none">> <br clear="none">> Adding an integer to a pointer "increments" it - the effect depends on the type<br clear="none">> of pointer.  Another way to think of it is that foo[1], say, is semantically<br clear="none">> identical to *(foo+1).<br clear="none">> <br clear="none">> cheers<br clear="none">> Miller<br clear="none">> <br clear="none">> On Mon, Aug 17, 2015 at 03:10:35PM +0000, Jonathan Wilkes via Pd-list wrote:<br clear="none">> > But we're dealing with an array of t_words, so onset*sizeof(t_word) is what we want anyway, no?<br clear="none">> > -Jonathan <br clear="none">> > <br clear="none">> > <br clear="none">> >      On Monday, August 17, 2015 10:55 AM, Claude Heiland-Allen <<a shape="rect" ymailto="mailto:claude@mathr.co.uk" href="mailto:claude@mathr.co.uk">claude@mathr.co.uk</a>> wrote:<br clear="none">> >    <br clear="none">> > <br clear="none">> >  On 17/08/15 15:36, Jonathan Wilkes via Pd-list wrote:<br clear="none">> > > Hi list,Wondering if someone will give me a free lesson in C programming.<br clear="none">> > > In g_traversal.c, there's some code to retrieve a float from a t_word* vec.  It looks like this:<br clear="none">> > > *(t_float *)(((char *)vec) + onset));<br clear="none">> > > 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...)<br clear="none">> > <br clear="none">> > aiui pointer arithmetic is in increments of sizeof(pointee)<br clear="none">> > if onset is measured in bytes (I don't know if it is in this case, but <br clear="none">> > it looks likely), then you need to have a pointer to bytes for the <br clear="none">> > addition to be meaningful.  vec is already a pointer, but adding onset <br clear="none">> > to a t_word* would offset the address by onset*sizeof(t_word) bytes<br clear="none">> > <br clear="none">> > <br clear="none">> > _______________________________________________<br clear="none">> > <a shape="rect" ymailto="mailto:Pd-list@lists.iem.at" href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br clear="none">> > UNSUBSCRIBE and account-management -> <a shape="rect" href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br clear="none">> > <br clear="none">> > <br clear="none">> >  <br clear="none">> <br clear="none">> > _______________________________________________<br clear="none">> > <a shape="rect" ymailto="mailto:Pd-list@lists.iem.at" href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br clear="none">> > UNSUBSCRIBE and account-management -> <a shape="rect" href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br clear="none">> <br clear="none">> <br clear="none">> <br clear="none">>   <br clear="none"><br clear="none">> _______________________________________________<br clear="none">> <a shape="rect" ymailto="mailto:Pd-list@lists.iem.at" href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br clear="none">> UNSUBSCRIBE and account-management -> <a shape="rect" href="http://lists.puredata.info/listinfo/pd-list" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br clear="none"><br clear="none"></div><br><br></div>  </div> </div>  </div></div></body></html>