<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>string constant in macro</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/42385/string-constant-in-macro</link><description> Hello, 
 
In my C code, I have: 
#define message 
message(&amp;quot;Start\n&amp;quot;); 
 
When I look at the SRC file, I see: 
 
	RSEG ?CO?MAIN 
?SC_0: 
	DB &amp;#39;S&amp;#39; ,&amp;#39;t&amp;#39; ,&amp;#39;a&amp;#39; ,&amp;#39;r&amp;#39; ,&amp;#39;t&amp;#39; ,00AH,000H 
 
; message(&amp;quot;Start\n&amp;quot;); 
 
Why does the C51 version 1.32 keep &amp;quot;Start\n&amp;quot; in</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/134398?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2004 12:46:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2e69b104-17a4-4e3f-b0da-61b23bad2362</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;I&amp;#39;d agree.&lt;br /&gt;
&lt;br /&gt;
(My previous post was answering the question asked, rather than recommending a strategy.  See the linked thread in which I make other comments.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/122433?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2004 07:28:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:066ee808-7e21-4b7e-b3d1-02effd6735a2</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;Sounds like a very bad idea to me.&lt;br /&gt;
&lt;br /&gt;
remember, it&amp;#39;s the preprocessor that does macro expansion, and it&amp;#39;s also the prepropcessor that strips comments...&lt;br /&gt;
&lt;br /&gt;
Far better to make your macro expansion explicitly &amp;amp; directly conditional (as described in the TRACE example), than rely on the order of macro &amp;quot;side-effects&amp;quot;...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/110949?ContentTypeID=1</link><pubDate>Sat, 03 Jul 2004 20:53:46 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:6479eeb3-b442-4d86-915a-3e980f136c28</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;How about:&lt;br /&gt;
&lt;br /&gt;
#define comment  /##/&lt;br /&gt;
&lt;br /&gt;
&amp;#39;##&amp;#39; is the &amp;quot;token pasting&amp;#39; operator that lets you glue bits together into a single token for the compiler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/96426?ContentTypeID=1</link><pubDate>Sat, 03 Jul 2004 19:29:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fd8b129a-d492-4aeb-9906-5377d3c21272</guid><dc:creator>Anh Phan</dc:creator><description>&lt;p&gt;Thanks guys,&lt;br /&gt;
&lt;br /&gt;
Your responses really help me a lot.  Looks like the TRACE macro is what I need to remove unnessary code.  Is there a way to expand a macro into // to comment out the code?&lt;br /&gt;
&lt;br /&gt;
Ex:&lt;br /&gt;
#define message //&lt;br /&gt;
&lt;br /&gt;
so that&lt;br /&gt;
&lt;br /&gt;
message(&amp;quot;Start\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
would expand to:&lt;br /&gt;
&lt;br /&gt;
//(&amp;quot;Start\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
Anh&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/86845?ContentTypeID=1</link><pubDate>Sat, 03 Jul 2004 00:50:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a68763ab-4ce4-4681-8151-35e087436198</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;I don&amp;#39;t know if this thread might help you:&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/forum/docs/thread3796.asp"&gt;http://www.keil.com/forum/docs/thread3796.asp&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
It shows (among other things) how to define a debug TRACE macro that can dissappear completely when  the code is built in non-debug mode.&lt;br /&gt;
The secret is in the use of an extra set of parenteses.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/42449?ContentTypeID=1</link><pubDate>Fri, 02 Jul 2004 23:19:49 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e35d9caf-43b5-4f8a-9908-5398cbe9e093</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;&lt;i&gt;Why does the C51 version 1.32 keep &amp;quot;Start\n&amp;quot; in the output? Does this also happen to newer version?&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
It does it because that is what you told the compiler to do.&lt;br /&gt;
&lt;br /&gt;
The line&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;#define message&lt;/pre&gt;
&lt;br /&gt;
defines a null macro for message.&lt;br /&gt;
&lt;br /&gt;
The line&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;message(&amp;quot;Start\n&amp;quot;);&lt;/pre&gt;
&lt;br /&gt;
expands as&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;(&amp;quot;Start\n&amp;quot;);&lt;/pre&gt;
&lt;br /&gt;
I can only assume that what you want is:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
#define message(x)
message(&amp;quot;Start\n&amp;quot;)
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/96430?ContentTypeID=1</link><pubDate>Fri, 02 Jul 2004 21:18:43 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:16c5db66-baf3-4499-9d61-8f86c9eaab1f</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;The macro expands to nothing, but the literal string constant still exists.&lt;br /&gt;
&lt;br /&gt;
How about another #define to make the constant vanish:&lt;br /&gt;
&lt;br /&gt;
//#define MessageString &amp;quot;Start\n&amp;quot;&lt;br /&gt;
#define MessageString&lt;br /&gt;
&lt;br /&gt;
#define message(a)&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
message(MessageString)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/72584?ContentTypeID=1</link><pubDate>Fri, 02 Jul 2004 20:04:32 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:51452629-385f-41ed-b95c-f45c2185f6e4</guid><dc:creator>Anh Phan</dc:creator><description>&lt;p&gt;What I mean is that I have the code:&lt;br /&gt;
&lt;br /&gt;
#define message&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
.&lt;br /&gt;
message(&amp;quot;Start\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
message(&amp;quot;Start\n&amp;quot;) should expands to nothing so &amp;quot;Start\n&amp;quot; should not be in the output&lt;br /&gt;
Anh&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: string constant in macro</title><link>https://community.arm.com/thread/42447?ContentTypeID=1</link><pubDate>Fri, 02 Jul 2004 19:11:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f03907a6-0d49-432d-9e54-eb04d1307ca1</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;Why does the C51 version 1.32 keep &amp;quot;Start\n&amp;quot; in the output?&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#39;t want it, why did you put it there?!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>