<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_1439836832374_32142">Thanks, Miller.  Seems every time I have a question about C, even forming the question requires me to relearn pointer arithmetic.</div><div id="yui_3_16_0_1_1439836832374_32143"><br></div><div id="yui_3_16_0_1_1439836832374_32144">-Jonathan<br></div><div id="yui_3_16_0_1_1439836832374_20473"><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 2:42 PM, Miller Puckette <msp@ucsd.edu> wrote:<br> </font> </div>  <br><br> <div class="y_msg_container">I can't remember why I thought that was the right thing to do... maybe I<br clear="none">was trying to keep the possibility open to pack the data more efficiently<br clear="none">(sticking two floats nto the size of one 'word').  But that seems like a<br clear="none">lot of awkwardness for not much payoff.  Maybe I had some other reason :)<br clear="none"><br clear="none">M<br clear="none"><br clear="none">On Mon, Aug 17, 2015 at 06:31:26PM +0000, Jonathan Wilkes via Pd-list wrote:<br clear="none">> Hi Spencer,The onset is in bytes, hence the cast to (char *).  I'm just wondering why we're measuring things in bytes since an onset must always lie on a t_word boundary.<br clear="none">> Thanks,Jonathan<br clear="none">>  <br clear="none">> <br clear="none">> <br clear="none">>      On Monday, August 17, 2015 2:29 PM, Jonathan Wilkes <<a shape="rect" ymailto="mailto:jancsika@yahoo.com" href="mailto:jancsika@yahoo.com">jancsika@yahoo.com</a>> wrote:<br clear="none">>    <br clear="none">> <br clear="none">>  I guess what I'm saying is that sc_vec is a loaf of bread, and the slices are t_word wide.  So why are we doing the bookeeping (i.e., jumping to a particular location) in units smaller than one slice?<br clear="none">> -Jonathan<br clear="none">> <br clear="none">> <br clear="none">>      On Monday, August 17, 2015 1:54 PM, Forrest Curo <<a shape="rect" ymailto="mailto:treegestalt@gmail.com" href="mailto:treegestalt@gmail.com">treegestalt@gmail.com</a>> wrote:<br clear="none">>    <br clear="none">> <br clear="none">>  *char is guaranteed to be the same size as a 'char', 8 bits -- but if you're treating t_word as an array of char's, you can get into t_word and process it in 8 bit chunks.<br clear="none">> <br clear="none">> On Mon, Aug 17, 2015 at 9:53 AM, Jonathan Wilkes via Pd-list <<a shape="rect" ymailto="mailto:pd-list@lists.iem.at" href="mailto:pd-list@lists.iem.at">pd-list@lists.iem.at</a>> wrote:<br clear="none">> <br clear="none">> Ah, ok-- I forgot my pointer arithmetic rules.<br clear="none">> 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).<br clear="none">> 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 clear="none">> <br clear="none">> -Jonathan<br clear="none">>  <br clear="none">> <br clear="none">> <br clear="none">>      On Monday, August 17, 2015 12:24 PM, 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">>  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">> <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><div class="yqt0582558715" id="yqtfd74583"><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">> <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">> <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>