<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
  <title>Linux Format forums</title>
  <link>http://www.linuxformat.com/forums/index.php</link>
  <description>Help, discussion, magazine feedback and more</description>
  <language>english</language>
  <copyright>(c) Copyright Thu May 23, 2013 2:36 am by Linux Format forums</copyright>
  <managingEditor>webmaster@linuxformat.com</managingEditor>
  <webMaster>webmaster@linuxformat.com</webMaster>
  <pubDate>Thu May 23, 2013 2:36 am</pubDate>
  <lastBuildDate>Thu May 23, 2013 2:36 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://www.linuxformat.com/forums/</link>
    <description>Help, discussion, magazine feedback and more</description>
  </image>

                                      <item>
                                        <title>RE: g++ macro help needed</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=29762#29762</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=9246'&gt;fpga&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Aug 18, 2006 4:23 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Thanks for the explanation.&lt;br /&gt;
I'll take your advice and try another approach.&lt;br /&gt;
Thanks</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=29762#29762</comments>
                                        <author>fpga</author>
                                        <pubDate>Fri Aug 18, 2006 4:23 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=29762#29762</guid>
                                      </item>
                                      <item>
                                        <title>RE: g++ macro help needed</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=29761#29761</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=162'&gt;Nigel&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Aug 18, 2006 3:22 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Hmm... trouble is that macros (as I understand them) are resolved at compile time. &lt;br /&gt;
As I read it, you want to create a function name from an object name by adding &quot;Rules&quot; onto the end of it. That won't work unless you have the name of the object at compile time - which you do when you just pass obj, but you don't when you pass a pointer to obj.&lt;br /&gt;
&lt;br /&gt;
So I think you're going to have to come at this one from another angle.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=29761#29761</comments>
                                        <author>Nigel</author>
                                        <pubDate>Fri Aug 18, 2006 3:22 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=29761#29761</guid>
                                      </item>
                                      <item>
                                        <title>RE: g++ macro help needed</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=29759#29759</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=9246'&gt;fpga&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Aug 18, 2006 1:57 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      Nigel &lt;br /&gt;
Thanks for your quick response.&lt;br /&gt;
The sticking point seems to be the ## concatenation operation &lt;br /&gt;
ie I can't convert anything other than 'obj' (supplied as an argument) so that &lt;br /&gt;
the ## statement ends up as :&lt;br /&gt;
'obj ## Rule' &lt;br /&gt;
ie the compiler always sees the first token as something other than obj.&lt;br /&gt;
This seems to be the case even when what is converted couts as obj</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=29759#29759</comments>
                                        <author>fpga</author>
                                        <pubDate>Fri Aug 18, 2006 1:57 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=29759#29759</guid>
                                      </item>
                                      <item>
                                        <title>RE: g++ macro help needed</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=29755#29755</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=162'&gt;Nigel&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Aug 18, 2006 1:10 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      I think the problem is that your macro is set up to receive the address of a structure. You want to pass the address of a pointer to the structure.&lt;br /&gt;
&lt;br /&gt;
Try this :&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;Myclass *pObj = &amp;amp;obj;&lt;br /&gt;
RULES_TO_OBJECTS &amp;#40;*obj&amp;#41;;&lt;/td&gt;	&lt;/tr&gt;&lt;/table&gt;&lt;span class=&quot;postbody&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
or possibly redefine your macro to expect a pointer to a structure and not a structure.</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=29755#29755</comments>
                                        <author>Nigel</author>
                                        <pubDate>Fri Aug 18, 2006 1:10 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=29755#29755</guid>
                                      </item>
                                      <item>
                                        <title>g++ macro help needed</title>
                                        <link>http://www.linuxformat.com/forums/viewtopic.php?p=29751#29751</link>
                                        <description>&lt;br /&gt;
                                      Author: &lt;a href='http://www.linuxformat.com/forums/profile.php?mode=viewprofile&amp;u=9246'&gt;fpga&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
                                      Posted: Fri Aug 18, 2006 12:27 pm&lt;br /&gt;&lt;br /&gt;
                                      &lt;br /&gt;&lt;br /&gt;
                                      /*&lt;br /&gt;
I'm trying to assign an ordinary function to a ptr in an object.&lt;br /&gt;
If I pass the objects name to the macro 'RULES_TO_OBJECTS'&lt;br /&gt;
explicitly, then the code works fine.&lt;br /&gt;
&lt;br /&gt;
I'd like to pass an object pointer to the macro instead, though, &lt;br /&gt;
but appear to be falling foul of a lack of macro expansion.&lt;br /&gt;
&lt;br /&gt;
Has anyone got a solution please?&lt;br /&gt;
Thanks in anticipation.&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
#define RULES_TO_OBJECTS(nm) {nm.pRule = nm ## Rule;}&lt;br /&gt;
&lt;br /&gt;
class Myclass {&lt;br /&gt;
	public:&lt;br /&gt;
		char * nam;&lt;br /&gt;
		int (*pRule)();&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
//Rule function created externally&lt;br /&gt;
int objRule() {cout &amp;lt;&amp;lt; 4 &amp;lt;&amp;lt;endl; return 4;}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	Myclass obj;  &lt;br /&gt;
&lt;br /&gt;
	//=============================&lt;br /&gt;
	// i'd like to replace this line&lt;br /&gt;
	RULES_TO_OBJECTS(obj);  &lt;br /&gt;
	//=============================&lt;br /&gt;
&lt;br /&gt;
	//=============================&lt;br /&gt;
	//with this&lt;br /&gt;
	//		Myclass * pObj = &amp;amp;obj;&lt;br /&gt;
	//		SOME_MACRO(pObj)&lt;br /&gt;
	//ie using a ptr to an object &amp;amp; get the same result&lt;br /&gt;
	//=============================&lt;br /&gt;
	obj.pRule();&lt;br /&gt;
}</description>
                                        <comments>http://www.linuxformat.com/forums/viewtopic.php?p=29751#29751</comments>
                                        <author>fpga</author>
                                        <pubDate>Fri Aug 18, 2006 12:27 pm</pubDate>
                                        <guid isPermaLink="true">http://www.linuxformat.com/forums/viewtopic.php?p=29751#29751</guid>
                                      </item></channel></rss>