<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Macros</title><link>https://sourceforge.net/p/typp/wiki/Macros/</link><description>Recent changes to Macros</description><atom:link href="https://sourceforge.net/p/typp/wiki/Macros/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 07 Jan 2016 11:57:33 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/typp/wiki/Macros/feed" rel="self" type="application/rss+xml"/><item><title>Macros modified by Cyder</title><link>https://sourceforge.net/p/typp/wiki/Macros/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;strong&gt;Macros&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Macros are the core feature of every preprocessor and TPP is no different. TPP implements keyword-style macros, function-style macro and variadic macros.&lt;/p&gt;
&lt;p&gt;As an extension to the c11 standard, TPP allows function macros, to call themselves recursively, as long as they change the call parameters. This is the core concept, that allows for macros like TPP_REPEAT from the standard library.&lt;/p&gt;
&lt;p&gt;For variadic macros, see &lt;a class="alink" href="/p/typp/wiki/VarArgs/"&gt;[VarArgs]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The following example shows a simple keyword-style macro being expanded:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;foobar // Expands to [foobar]
#define foobar 42
foobar // Expands to [42]
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Function style macros can be defined, by typing a &lt;code&gt;(&lt;/code&gt; directly after the macro name:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt; &lt;span class="nx"&gt;not_a_function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;define&lt;/span&gt;       &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;

&lt;span class="nx"&gt;not_a_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Expands to &lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt; &lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="cp"&gt;][&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="c1"&gt;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Expands to &lt;/span&gt;&lt;span class="cp"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="cp"&gt;]&lt;/span&gt;&lt;span class="c1"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Macros defined by the user can later be undefined, using the &lt;code&gt;#undef directive&lt;/code&gt;:&lt;br/&gt;
Hint: TPP includes a warning (36), when undefining a macro, that doesn't exist, but this warning is disabled by default&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;#define foobar 42
#undef foobar
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;s.a. &lt;a class="alink" href="/p/typp/wiki/VarArgs/"&gt;[VarArgs]&lt;/a&gt;&lt;br/&gt;
s.a. &lt;a class="alink" href="/p/typp/wiki/Bracket%20notation/"&gt;[Bracket notation]&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Cyder</dc:creator><pubDate>Thu, 07 Jan 2016 11:57:33 -0000</pubDate><guid>https://sourceforge.net0e51f7f404e58c57d6af912e51b5626db67353f3</guid></item></channel></rss>