<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with macros C in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268736#M10107</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you all for your help and time.&lt;/P&gt;&lt;P&gt;Erich thanks for info.&lt;/P&gt;&lt;P&gt;Petr, I will change the code like you suggested. Carlh, the brackets didn't help but thanks anyway for your time :smileyhappy:.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Florijan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Apr 2013 19:01:58 GMT</pubDate>
    <dc:creator>Florijan</dc:creator>
    <dc:date>2013-04-16T19:01:58Z</dc:date>
    <item>
      <title>Help with macros C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268732#M10103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code:&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#define SET_BIT(reg,bit_no)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;|&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;= (1&amp;lt;&amp;lt;bit_no)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;#define TRANSMITTER_ENABLE_BIT&amp;nbsp;&amp;nbsp; SCI2C2, 7&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;void main(void){&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET_BIT(TRANSMITTER_ENABLE_BIT);&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With this code I want to put two arguments SCI2C2 and 7 into SET_BIT() macro. But the compiler says that there is only one argument detected instead of two in the line SET_BIT(TRANSMITTER_ENABLE_BIT);.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please tell me how to pass two arguments to &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;macro&amp;nbsp;&amp;nbsp; SET_BIT&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;() ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Florijan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 13:15:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268732#M10103</guid>
      <dc:creator>Florijan</dc:creator>
      <dc:date>2013-04-16T13:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macros C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268733#M10104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;While with C preprocessing things are 'textually' replaced, this does not apply to the macro argument expansion. You cannot pass an argument which then is expanded in to a list of argument (what you have in your code).&lt;/P&gt;&lt;P&gt;You need to supply the right number of arguments. What you could do is pass an 'empty' argument, as&lt;/P&gt;&lt;P&gt;SET_BIT(TRANSMITTER_ENABLE_BIT,);&lt;/P&gt;&lt;P&gt;(note the comma, for an 'empty' argument.&lt;/P&gt;&lt;P&gt;I think you need to rewrite your code as such that it is using two arguments.&lt;/P&gt;&lt;P&gt;Unless someone else has a different solution?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 13:41:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268733#M10104</guid>
      <dc:creator>BlackNight</dc:creator>
      <dc:date>2013-04-16T13:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macros C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268734#M10105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wouldn't brackets help here?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#define TRANSMITTER_ENABLE_BIT&amp;nbsp;&amp;nbsp; (SCI2C2, 7)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 14:00:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268734#M10105</guid>
      <dc:creator>carlh</dc:creator>
      <dc:date>2013-04-16T14:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macros C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268735#M10106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Florijan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't think you can do so since function-like macros are evaluated from outside in, as explained here: &lt;A href="http://home.datacomm.ch/t_wolf/tw/c/macro_eval.html" title="http://home.datacomm.ch/t_wolf/tw/c/macro_eval.html"&gt;Macro Call as Macro Argument&lt;/A&gt; . Hence SET_BIT is evaluated first, the preprocessor sees it requires two arguments, but only one is found. It ends up with error without evaluating the inner macro (TRANSMITTER_ENABLE_BIT).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see only two solutions:&lt;/P&gt;&lt;P&gt;1:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define SET_BIT(reg,bit_no)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;|&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;= (1&amp;lt;&amp;lt;bit_no)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define TRANSMITTER_ENABLE_REG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SCI2C2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define TRANSMITTER_ENABLE_BIT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void main(void){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET_BIT(TRANSMITTER_ENABLE_REG, TRANSMITTER_ENABLE_BIT);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;2:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define SET_BIT(reg,bit_no)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; reg&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;|&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;= (1&amp;lt;&amp;lt;bit_no)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#define TRANSMITTER_ENABLE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SET_BIT(SCI2C2,7)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&amp;nbsp; &lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void main(void){&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TRANSMITTER_ENABLE();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 14:01:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268735#M10106</guid>
      <dc:creator>kubiznak_petr</dc:creator>
      <dc:date>2013-04-16T14:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: Help with macros C</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268736#M10107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you all for your help and time.&lt;/P&gt;&lt;P&gt;Erich thanks for info.&lt;/P&gt;&lt;P&gt;Petr, I will change the code like you suggested. Carlh, the brackets didn't help but thanks anyway for your time :smileyhappy:.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Florijan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Apr 2013 19:01:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Help-with-macros-C/m-p/268736#M10107</guid>
      <dc:creator>Florijan</dc:creator>
      <dc:date>2013-04-16T19:01:58Z</dc:date>
    </item>
  </channel>
</rss>

