<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Sun May 26, 2013 1:44 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Sun May 26, 2013 1:44 am</pubDate>
  <lastBuildDate>Sun May 26, 2013 1:44 am</lastBuildDate>
  <docs>http://backend.userland.com/rss</docs>
  <generator>phpBB2 RSS Syndication Mod by Lucas</generator>
  <ttl>1</ttl>

  <image>
    <title>Linux Format forums</title>
    <url></url>
    <link>http://linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>Re: C++ macros</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=4232#4232</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=133'&gt;jjmac&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Jul 01, 2005 11:55 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      &amp;gt;&amp;gt;&lt;br /&gt;
The reason I didn't use a vector is that the struct that I'm coping to is already define, and I don't have control over it &lt;img src=&quot;images/smiles/icon_sad.gif&quot; alt=&quot;Sad&quot; border=&quot;0&quot; /&gt; &lt;br /&gt;
&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Arrha, i see &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
The &quot;switch&quot; will work though, it's just that the preproccesor will need a const at compile-time, for the substitution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
jm</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=4232#4232</comments>
                                        <author>jjmac</author>
                                        <pubDate>Fri Jul 01, 2005 11:55 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=4232#4232</guid>
                                      </item>
                                      <item>
                                        <title>Re: C++ macros</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=4167#4167</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=148'&gt;tedius&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Thu Jun 30, 2005 2:18 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thanks for the help guys.&lt;br /&gt;
&lt;br /&gt;
I had sort of come to the conclusion that what I was trying was not going to work  &lt;img src=&quot;images/smiles/icon_sad.gif&quot; alt=&quot;Sad&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
The solution that I am using is just to remove it from the loop and do one line for each copy.  It works, but with 34 attributes to copy I was hoping for something more cleaver. &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
jjmac.&lt;br /&gt;
&lt;br /&gt;
The reason I didn't use a vector is that the struct that I'm coping to is already define, and I don't have control over it &lt;img src=&quot;images/smiles/icon_sad.gif&quot; alt=&quot;Sad&quot; border=&quot;0&quot; /&gt;</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=4167#4167</comments>
                                        <author>tedius</author>
                                        <pubDate>Thu Jun 30, 2005 2:18 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=4167#4167</guid>
                                      </item>
                                      <item>
                                        <title>RE: C++ macros</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=4148#4148</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=133'&gt;jjmac&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Jun 29, 2005 11:16 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thats a really good problem &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
But, as suggested above ... the preprocessor can only reall do a compile-time substitution. And it will require a 'constant' to use in the substitution.&lt;br /&gt;
&lt;br /&gt;
Where as, your looking for a run-time evaluation. I don't think the preprocessor can do that.&lt;br /&gt;
&lt;br /&gt;
You would need to provide some trick to allow for a 'constant' to be passes, like the below.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for &amp;#40;int i = 1; i &amp;lt;= 3; i++&amp;#41;&amp;#123; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; switch &amp;#40;i&amp;#41;&amp;#123;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case 1&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; COPY_ATT&amp;#40;ob-&amp;gt;att_1, i, i&amp;#41;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case 2&amp;#58;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; COPY_ATT&amp;#40;ob-&amp;gt;att_2, i, i&amp;#41;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;#125;&lt;br /&gt;
&amp;nbsp; &amp;#125;&lt;br /&gt;
&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
That could get somewhat messy if you had a lot of strings to copy. &lt;br /&gt;
&lt;br /&gt;
As a container ... why not use a 'vector' instead ?. Sounds like it would be perfect for what you see, to be doing there.&lt;br /&gt;
&lt;br /&gt;
About all i know about macro substitions though, comes from here ...&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://gcc.gnu.org/onlinedocs/cpp/Macros.html&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://gcc.gnu.org/onlinedocs/cpp/Macros.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
So i could well be missing something there &lt;img src=&quot;images/smiles/icon_smile.gif&quot; alt=&quot;Smile&quot; border=&quot;0&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
jm</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=4148#4148</comments>
                                        <author>jjmac</author>
                                        <pubDate>Wed Jun 29, 2005 11:16 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=4148#4148</guid>
                                      </item>
                                      <item>
                                        <title>RE: C++ macros</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=4141#4141</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=1772'&gt;vorian&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Wed Jun 29, 2005 9:30 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Macros are evaluated by the preprocessor not the core compiler. You should treat it like string substitution. &lt;br /&gt;
After the preprocessing stage your code looks like:&lt;br /&gt;
for (i = 1; i &amp;lt;= 3; i++)&lt;br /&gt;
    copyAtt((dest)-&amp;gt;att_i, \&lt;br /&gt;
               list,&lt;br /&gt;
               i);&lt;br /&gt;
now the core compiler gets to work and seeks to find a att_i attribute (there is none ).</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=4141#4141</comments>
                                        <author>vorian</author>
                                        <pubDate>Wed Jun 29, 2005 9:30 pm</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=4141#4141</guid>
                                      </item>
                                      <item>
                                        <title>C++ macros</title>
                                        <link>http://linuxformat.com/forums/viewtopic.php?p=4013#4013</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=148'&gt;tedius&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Mon Jun 27, 2005 11:34 am&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I'm trying to write a macro that will call a function to copy some values.&lt;br /&gt;
The extract below is only a small part of my program but I hope it will give you the idea of what I'm trying to do.&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;#define COPY_ATT&amp;#40;dest, source, num&amp;#41; \&lt;br /&gt;
&amp;nbsp; copyAtt&amp;#40;&amp;#40;dest&amp;#41;-&amp;gt;att_ ## num, \&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;source,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;num&amp;#41;;&lt;br /&gt;
&lt;br /&gt;
std&amp;#58;&amp;#58;string&amp;#91;3&amp;#93; list;&lt;br /&gt;
&lt;br /&gt;
class object&lt;br /&gt;
&amp;#123;&lt;br /&gt;
&amp;nbsp; std&amp;#58;&amp;#58;string att_1;&lt;br /&gt;
&amp;nbsp; std&amp;#58;&amp;#58;string att_2;&lt;br /&gt;
&amp;nbsp; std&amp;#58;&amp;#58;string att_3;&lt;br /&gt;
&amp;#125;;&lt;br /&gt;
&lt;br /&gt;
copyAtt&amp;#40;std&amp;#58;&amp;#58;string att,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; std&amp;#58;&amp;#58;string&amp;#91;&amp;#93; list,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int index&amp;#41;&lt;br /&gt;
&amp;#123;&lt;br /&gt;
&amp;nbsp; &amp;nbsp;att = list&amp;#91;num-1&amp;#93;;&lt;br /&gt;
&amp;#125;&lt;br /&gt;
&lt;br /&gt;
int main&amp;#40;&amp;#41;&lt;br /&gt;
&amp;#123;&lt;br /&gt;
&amp;nbsp; object *pObj new object;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; for &amp;#40;i = 1; i &amp;lt;= 3; i++&amp;#41;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; COPY_ATT&amp;#40;obj, list, i&amp;#41;;&lt;br /&gt;
&amp;#125;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
What is happening is that the macro is evaluating to (on the first loop)&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;copyAtt&amp;#40;pObj-&amp;gt;att_i,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; list,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;#41;;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Where I was hopping for&lt;br /&gt;
&lt;/span&gt;&lt;table width=&quot;90%&quot; cellspacing=&quot;1&quot; cellpadding=&quot;3&quot; border=&quot;0&quot; align=&quot;center&quot;&gt;&lt;tr&gt; 	  &lt;td&gt;&lt;span class=&quot;genmed&quot;&gt;&lt;b&gt;Code:&lt;/b&gt;&lt;/span&gt;&lt;/td&gt;	&lt;/tr&gt;	&lt;tr&gt;	  &lt;td class=&quot;code&quot;&gt;copyAtt&amp;#40;pObj-&amp;gt;att_1,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; list,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;#41;;&lt;br /&gt;
&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
Is it at all posible to do what I want, and if so can some one tell me where I'm going wong.&lt;br /&gt;
&lt;br /&gt;
Thanks</description>
                                        <comments>http://linuxformat.com/forums/viewtopic.php?p=4013#4013</comments>
                                        <author>tedius</author>
                                        <pubDate>Mon Jun 27, 2005 11:34 am</pubDate>
                                        <guid isPermaLink="true">http://linuxformat.com/forums/viewtopic.php?p=4013#4013</guid>
                                      </item></channel></rss>