<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div dir="ltr" id="yui_3_16_0_1_1439825580628_8522">Thanks, I think I'm getting it.<br></div><div id="yui_3_16_0_1_1439825580628_9027">So is char* guaranteed to be the same width as sizeof(t_word)?  If so, are you just using it as a shorthand?<br></div><div id="yui_3_16_0_1_1439825580628_8523"><br></div><div id="yui_3_16_0_1_1439825580628_9028">Thanks,<br></div><div id="yui_3_16_0_1_1439825580628_8525">Jonathan<br></div><div id="yui_3_16_0_1_1439825580628_9029"><br></div><div id="yui_3_16_0_1_1439825580628_9030"><br></div><div id="yui_3_16_0_1_1439825580628_9031"><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 11:31 AM, Miller Puckette <msp@ucsd.edu> wrote:<br> </font> </div>  <br><br> <div class="y_msg_container">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"><div class="yqt6789626297" id="yqtfd86413"><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 href="" class="removed-link" shape="rect" ymailto="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 href="" class="removed-link" shape="rect" ymailto="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br clear="none">> UNSUBSCRIBE and account-management -> <a href="" class="removed-link" shape="rect" 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 href="" class="removed-link" shape="rect" ymailto="mailto:Pd-list@lists.iem.at">Pd-list@lists.iem.at</a> mailing list<br clear="none">> UNSUBSCRIBE and account-management -> <a href="" class="removed-link" shape="rect" 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>