<?xml version="1.0" encoding="UTF-8"?>
	<rss version="2.0"
		xmlns:content="http://purl.org/rss/1.0/modules/content/"
		xmlns:wfw="http://wellformedweb.org/CommentAPI/"
		xmlns:dc="http://purl.org/dc/elements/1.1/"
		xmlns:atom="http://www.w3.org/2005/Atom"

			>

	<channel>
		<title>Cycling 74  &#187;  Topic: How to get the nth element of a list ?</title>
		<atom:link href="http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/feed" rel="self" type="application/rss+xml" />
		<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/feed</link>
		<description></description>
		<pubDate>Wed, 19 Jun 2013 19:14:42 +0000</pubDate>
		<generator>http://bbpress.org/?v=2.2.4</generator>
		<language></language>

		
														
					
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-34630</guid>
					<title><![CDATA[How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-34630</link>
					<pubDate>Fri, 16 Nov 2007 12:34:14 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p>Dear list,</p>
<p>I want to convert the second element of a list of atoms, to a float<br />
and it&#8217;s driving me crazy. I can only get the first one to work,<br />
everything else i try gives me the address of the pointer instead.</p>
<p>Please help</p>
<p>My list is Atom *av</p>
<p>float target = 0;<br />
target = av->a_w.w.float;<br />
outlet_float(x->t_floatout, target);</p>
<p>gives me the first member of the list. How to get the second one ?</p>
<p>f.e</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117217</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117217</link>
					<pubDate>Fri, 16 Nov 2007 12:48:07 +0000</pubDate>
					<dc:creator>ebmoluoc</dc:creator>

					<description>
						<![CDATA[
						<p>Try this:</p>
<p>float target;<br />
target = av[1].a_w.w_float;<br />
outlet_float(x->t_floatout, target);</p>
<p>On Nov 16, 2007 7:34 AM, f.e
<personalcomputermusic @gmail.com> wrote:<br />
> Dear list,<br />
><br />
> I want to convert the second element of a list of atoms, to a float<br />
> and it&#8217;s driving me crazy. I can only get the first one to work,<br />
> everything else i try gives me the address of the pointer instead.<br />
><br />
> Please help<br />
><br />
> My list is Atom *av<br />
><br />
> float target = 0;<br />
> target = av->a_w.w.float;<br />
> outlet_float(x->t_floatout, target);<br />
><br />
> gives me the first member of the list. How to get the second one ?<br />
><br />
> f.e<br />
></personalcomputermusic></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117218</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117218</link>
					<pubDate>Fri, 16 Nov 2007 12:55:50 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p>It&#8217;s the first thing i&#8217;ve done but it doesn&#8217;t work. It should but it<br />
doesn&#8217;t. It gives me something like-15048510125 instead of 1.0</p>
<p>f.e</p>
<p>
On Nov 16, 2007 1:48 PM, P C <ebmoluoc @gmail.com> wrote:<br />
> Try this:<br />
><br />
> float target;<br />
> target = av[1].a_w.w_float;<br />
> outlet_float(x->t_floatout, target);<br />
><br />
><br />
><br />
><br />
> On Nov 16, 2007 7:34 AM, f.e
<personalcomputermusic @gmail.com> wrote:<br />
> > Dear list,<br />
> ><br />
> > I want to convert the second element of a list of atoms, to a float<br />
> > and it&#8217;s driving me crazy. I can only get the first one to work,<br />
> > everything else i try gives me the address of the pointer instead.<br />
> ><br />
> > Please help<br />
> ><br />
> > My list is Atom *av<br />
> ><br />
> > float target = 0;<br />
> > target = av->a_w.w.float;<br />
> > outlet_float(x->t_floatout, target);<br />
> ><br />
> > gives me the first member of the list. How to get the second one ?<br />
> ><br />
> > f.e<br />
> ><br />
></personalcomputermusic></ebmoluoc></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117219</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117219</link>
					<pubDate>Fri, 16 Nov 2007 13:18:41 +0000</pubDate>
					<dc:creator>ebmoluoc</dc:creator>

					<description>
						<![CDATA[
						<p>Replace float by double.<br />
as this:</p>
<p>double target = av[1].a_w.w_float;</p>
<p>
On Nov 16, 2007 7:55 AM, f.e
<personalcomputermusic @gmail.com> wrote:<br />
> It&#8217;s the first thing i&#8217;ve done but it doesn&#8217;t work. It should but it<br />
> doesn&#8217;t. It gives me something like-15048510125 instead of 1.0<br />
><br />
> f.e<br />
><br />
><br />
><br />
> On Nov 16, 2007 1:48 PM, P C <ebmoluoc @gmail.com> wrote:<br />
> > Try this:<br />
> ><br />
> > float target;<br />
> > target = av[1].a_w.w_float;<br />
> > outlet_float(x->t_floatout, target);<br />
> ><br />
> ><br />
> ><br />
> ><br />
> > On Nov 16, 2007 7:34 AM, f.e
<personalcomputermusic @gmail.com> wrote:<br />
> > > Dear list,<br />
> > ><br />
> > > I want to convert the second element of a list of atoms, to a float<br />
> > > and it&#8217;s driving me crazy. I can only get the first one to work,<br />
> > > everything else i try gives me the address of the pointer instead.<br />
> > ><br />
> > > Please help<br />
> > ><br />
> > > My list is Atom *av<br />
> > ><br />
> > > float target = 0;<br />
> > > target = av->a_w.w.float;<br />
> > > outlet_float(x->t_floatout, target);<br />
> > ><br />
> > > gives me the first member of the list. How to get the second one ?<br />
> > ><br />
> > > f.e<br />
> > ><br />
> ><br />
></personalcomputermusic></ebmoluoc></personalcomputermusic></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117220</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117220</link>
					<pubDate>Fri, 16 Nov 2007 13:32:12 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 16 nov. 07, at 14:18, P C wrote:</p>
<p>> Replace float by double.<br />
> as this:<br />
><br />
> double target = av[1].a_w.w_float;</p>
<p>Something like that should work, unless I miss typed something.</p>
<p>void myobject_toto(t_myobject *x, t_symbol *s, long argc, t_atom *argv)<br />
{<br />
	double f;</p>
<p>	if (argv &#038;&#038; argv) {<br />
		f = atom_getfloat(&#038;argv[0]);<br />
		outlet(x->floatout, f);<br />
	}<br />
}</p>
<p>
ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117221</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117221</link>
					<pubDate>Fri, 16 Nov 2007 14:41:52 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p>Incredible. It works with double !</p>
<p>Something else : this few lines of codes were placed AFTER a for to<br />
loop (reading all the atoms), and, for an unknown reason, av[1] was<br />
giving me av[7] instead. I move these lines BEFORE the for to loop,<br />
and it works again&#8230; Weird, isn&#8217;t it ?</p>
<p>Thanks a lot, anyway</p>
<p>f.e</p>
<p>On Nov 16, 2007 2:32 PM, Emmanuel Jourdan <c74 -mailinglists@e--j.com> wrote:<br />
> On 16 nov. 07, at 14:18, P C wrote:<br />
><br />
> > Replace float by double.<br />
> > as this:<br />
> ><br />
> > double target = av[1].a_w.w_float;<br />
><br />
> Something like that should work, unless I miss typed something.<br />
><br />
> void myobject_toto(t_myobject *x, t_symbol *s, long argc, t_atom *argv)<br />
> {<br />
>         double f;<br />
><br />
>         if (argv &#038;&#038; argv) {<br />
>                 f = atom_getfloat(&#038;argv[0]);<br />
>                 outlet(x->floatout, f);<br />
>         }<br />
> }<br />
><br />
><br />
> ej<br />
><br />
></c74></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117222</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117222</link>
					<pubDate>Fri, 16 Nov 2007 15:05:17 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 16 nov. 07, at 15:41, f.e wrote:</p>
<p>> Incredible. It works with double !<br />
><br />
> Something else : this few lines of codes were placed AFTER a for to<br />
> loop (reading all the atoms), and, for an unknown reason, av[1] was<br />
> giving me av[7] instead. I move these lines BEFORE the for to loop,<br />
> and it works again&#8230; Weird, isn&#8217;t it ?</p>
<p>Could you post this extract of the code?</p>
<p>ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117223</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117223</link>
					<pubDate>Fri, 16 Nov 2007 22:01:49 +0000</pubDate>
					<dc:creator>Peter Castine</dc:creator>

					<description>
						<![CDATA[
						<p>You must always use &#8216;double&#8217; for parameters on Windows. Most (all?) modern Mac compilers pass &#8216;float&#8217; parameters as 64-bit registers, most Windows compilers still pass &#8216;float&#8217; parameters as 32-bit values. Vive la difference?</p>
<p>About your loop: if it&#8217;s incrementing the base address of av, well av[1] is going to mean something different after the loop than it did before. Incrementing the base address of an array is a vile and error-prone programming habit, but unfortunately most C programmers are addicted to it.</p>
<p>  // The following is code to crash &#038; die for<br />
  void foo(Object *x, short ac, Atom *av)<br />
  {<br />
  long x, y;</p>
<p>  // av points to a vector of Atoms<br />
  x = av[0].a_w.w_long;</p>
<p>  while (i&#8211; > 0) {<br />
    av++;<br />
    }<br />
  // If (i>0) av now points to a *different* address<br />
  y = av[0].a_w.w_long;</p>
<p>  ASSERT (probably_not_equal(x, y));<br />
  }</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117224</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117224</link>
					<pubDate>Sat, 17 Nov 2007 11:26:06 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117225</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117225</link>
					<pubDate>Sat, 17 Nov 2007 11:30:28 +0000</pubDate>
					<dc:creator>Jeremy Bernstein</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117226</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117226</link>
					<pubDate>Sat, 17 Nov 2007 11:33:02 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117227</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117227</link>
					<pubDate>Sat, 17 Nov 2007 11:45:23 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117228</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117228</link>
					<pubDate>Sat, 17 Nov 2007 11:57:28 +0000</pubDate>
					<dc:creator>Jeremy Bernstein</dc:creator>

					<description>
						<![CDATA[
						<p>
Am 17.11.2007 um 12:45 schrieb f.e:</p>
<p>> Correct me if i&#8217;m wrong, this is not what i do there ? (because  <br />
> here it&#8217;s called l_templistout) :<br />
><br />
> typedef struct _vcparse<br />
> {<br />
> 	t_object	m_ob;			<br />
> 	void 		*t_intout;<br />
> 	void		*t_listout;<br />
> 	t_atom		l_templistout[8];<br />
> } t_vcparse;</p>
<p>Yes, here you are allocating an array of 8 t_atoms.</p>
<p>> And, like a fool, i declare<br />
><br />
> t_atom	*templistout;</p>
<p>Here, you are declaring a (global) t_atom * (4 bytes on a 32-bit OS),  <br />
which you can later use to store the value of an allocated pointer.  <br />
For instance:</p>
<p>templistout = (t_atom *)sysmem_newptr(sizeof(t_atom) * 8);</p>
<p>But until you&#8217;ve assigned templistout to a block of allocated memory,  <br />
you should&#8217;t try to read or write from it (as it isn&#8217;t pointing to  <br />
anything valid).</p>
<p>I wouldn&#8217;t use a global variable for this, anyway, but I think you  <br />
understand that.</p>
<p>Changing your code (just email typing &#8212; not verified that it works):</p>
<p>void vcparse_list(t_vcparse *x, Symbol *s, int ac, Atom *av)<br />
{<br />
     int i;<br />
     int j = 3;<br />
     short target = 0;<br />
     t_atom templistout[8]; // in this case is the easier solution<br />
     // OR<br />
     // t_atom *templistout = (t_atom *)sysmem_newptr(sizeof(t_atom)  <br />
* 8); // better for dynamic sized templist &#8212; don&#8217;t forget to free  <br />
with sysmem_freeptr();</p>
<p>     if ((ac==34) &#038; (av[1].a_w.w_float!=0))       {<br />
         for (i=0;i&lt;8;i++)<br />
         {<br />
             SETFLOAT(&#038;templistout[i], av[j].a_w.w_float);<br />
             j = j+4;<br />
         }</p>
<p>         target = (short) av[1].a_w.w_float;<br />
         outlet_int(x->t_intout, target);<br />
         outlet_list(x->t_listout, 0L, 8, templistout);<br />
     }<br />
     else if ((ac==34) &#038; (av[1].a_w.w_float==0))<br />
     {<br />
         post(&#8220;[sd.vc.parse] ERROR ! Packet dropped because target 0  <br />
received&#8221;);<br />
     }<br />
     else if (ac==6)<br />
     {<br />
         post(&#8220;[sd.vc.parse] ERROR ! Packet dropped because source  <br />
coordinates received&#8221;);<br />
     }<br />
     else post(&#8220;[sd.vc.parse] ERROR ! Packet dropped because list too  <br />
short (%d)&#8221;, ac);<br />
}</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117229</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117229</link>
					<pubDate>Sat, 17 Nov 2007 12:39:02 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117230</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117230</link>
					<pubDate>Sat, 17 Nov 2007 16:29:57 +0000</pubDate>
					<dc:creator>Patrick Delges</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117231</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117231</link>
					<pubDate>Sat, 17 Nov 2007 17:06:33 +0000</pubDate>
					<dc:creator>Peter Castine</dc:creator>

					<description>
						<![CDATA[
						<p>First of all, now that I see your code I see your problem was different from what I had guessed. My mistake for not waiting to see what your problem really was.</p>
<p>However, to pick up on your question about my example (which is quite likely to happen to a beginner copying and modifying existing C code), there are several ways to avoid the problem I focussed on. One would be as follows:</p>
<p>========================</p>
<p>void foo(Object *x, short ac, Atom *av)<br />
{<br />
long x, y, j;</p>
<p>// av points to a vector of Atoms<br />
x = av[0].a_w.w_long;</p>
<p>j = 0;<br />
while (j < ac) { // this was a typo in prev. example<br />
long z = av[j++].a_w.w_long;<br />
// Real code would do something with the data here<br />
}</p>
<p>// av hasn&#8217;t changed, so the following works as expected<br />
y = av[0].a_w.w_long;</p>
<p>ASSERT (absolutely_definitely_equal(x, y));<br />
}</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</p>
<p>As a matter of principal I always declare my argc/argv functions something like the following:</p>
<p>void foo(Object* x, short ac, Atom av[])</p>
<p>Declaring av as an array of Atoms (rather than a pointer to an Atom) serves as a reminder to me about what&#8217;s being passed. And I never move the base address. That comes from training in Pascal. C programmers liked to treat arrays as movable pointers because they could get marginally better performance that way with early C compilers. Modern optimizing C compilers will, as a rule, generate equally efficient machine code with either this example or the code I sent yesterday.</p>
<p>Hope this little tangent is helpful.</p>
<p>&#8211; P.</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117232</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117232</link>
					<pubDate>Thu, 22 Nov 2007 11:41:12 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117233</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117233</link>
					<pubDate>Thu, 22 Nov 2007 11:51:53 +0000</pubDate>
					<dc:creator>Emmanuel Jourdan</dc:creator>

					<description>
						<![CDATA[
						<p>On 22 nov. 07, at 12:41, f.e wrote:</p>
<p>> In the case i use :<br />
><br />
> t_atom *templistout = (t_atom *)sysmem_newptr(sizeof(t_atom) * 8);<br />
><br />
> Only things i have to do is :<br />
><br />
> sysmem_freeptr(templistout);</p>
<p>Exactly.</p>
<p>ej</p>
						]]>
					</description>

					
					
				</item>

			
				<item>
					<guid>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117234</guid>
					<title><![CDATA[Re: How to get the nth element of a list ?]]></title>
					<link>http://cycling74.com/forums/topic/how-to-get-the-nth-element-of-a-list/#post-117234</link>
					<pubDate>Thu, 22 Nov 2007 11:55:46 +0000</pubDate>
					<dc:creator>f.e</dc:creator>

					<description>
						<![CDATA[
						<p></p>
						]]>
					</description>

					
					
				</item>

					
		
	</channel>
	</rss>

