<div dir="ltr">*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></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 17, 2015 at 9:53 AM, Jonathan Wilkes via Pd-list <span dir="ltr"><<a href="mailto:pd-list@lists.iem.at" target="_blank">pd-list@lists.iem.at</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;font-size:16px"><div dir="ltr">Ah, ok-- I forgot my pointer arithmetic rules.<br></div><div 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 dir="ltr"><br></div><div 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?<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div dir="ltr"><br></div><div dir="ltr">-Jonathan<br></div></font></span><div><div class="h5"><div><span></span></div>  <br><div><br><br></div><div style="display:block"> <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 <<a href="mailto:msp@ucsd.edu" target="_blank">msp@ucsd.edu</a>> wrote:<br> </font> </div>  <br><br> <div>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><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" href="mailto:msp@ucsd.edu" target="_blank">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" href="mailto:claude@mathr.co.uk" target="_blank">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" href="mailto:Pd-list@lists.iem.at" target="_blank">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" href="mailto:Pd-list@lists.iem.at" target="_blank">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" href="mailto:Pd-list@lists.iem.at" target="_blank">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></div></div></div><br>_______________________________________________<br>
<a href="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br>
UNSUBSCRIBE and account-management -> <a href="http://lists.puredata.info/listinfo/pd-list" rel="noreferrer" target="_blank">http://lists.puredata.info/listinfo/pd-list</a><br>
<br></blockquote></div><br></div>