1<html lang="en"> 2<head> 3<title>Macros - The C Preprocessor</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="The C Preprocessor"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="prev" href="Header-Files.html#Header-Files" title="Header Files"> 9<link rel="next" href="Conditionals.html#Conditionals" title="Conditionals"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 131997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 142008, 2009, 2010, 2011 15Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation. A copy of 20the license is included in the 21section entitled ``GNU Free Documentation License''. 22 23This manual contains no Invariant Sections. The Front-Cover Texts are 24(a) (see below), and the Back-Cover Texts are (b) (see below). 25 26(a) The FSF's Front-Cover Text is: 27 28 A GNU Manual 29 30(b) The FSF's Back-Cover Text is: 31 32 You have freedom to copy and modify this GNU Manual, like GNU 33 software. Copies published by the Free Software Foundation raise 34 funds for GNU development. 35--> 36<meta http-equiv="Content-Style-Type" content="text/css"> 37<style type="text/css"><!-- 38 pre.display { font-family:inherit } 39 pre.format { font-family:inherit } 40 pre.smalldisplay { font-family:inherit; font-size:smaller } 41 pre.smallformat { font-family:inherit; font-size:smaller } 42 pre.smallexample { font-size:smaller } 43 pre.smalllisp { font-size:smaller } 44 span.sc { font-variant:small-caps } 45 span.roman { font-family:serif; font-weight:normal; } 46 span.sansserif { font-family:sans-serif; font-weight:normal; } 47--></style> 48<link rel="stylesheet" type="text/css" href="../cs.css"> 49</head> 50<body> 51<div class="node"> 52<a name="Macros"></a> 53<p> 54Next: <a rel="next" accesskey="n" href="Conditionals.html#Conditionals">Conditionals</a>, 55Previous: <a rel="previous" accesskey="p" href="Header-Files.html#Header-Files">Header Files</a>, 56Up: <a rel="up" accesskey="u" href="index.html#Top">Top</a> 57<hr> 58</div> 59 60<h2 class="chapter">3 Macros</h2> 61 62<p>A <dfn>macro</dfn> is a fragment of code which has been given a name. 63Whenever the name is used, it is replaced by the contents of the macro. 64There are two kinds of macros. They differ mostly in what they look 65like when they are used. <dfn>Object-like</dfn> macros resemble data objects 66when used, <dfn>function-like</dfn> macros resemble function calls. 67 68 <p>You may define any valid identifier as a macro, even if it is a C 69keyword. The preprocessor does not know anything about keywords. This 70can be useful if you wish to hide a keyword such as <code>const</code> from an 71older compiler that does not understand it. However, the preprocessor 72operator <code>defined</code> (see <a href="Defined.html#Defined">Defined</a>) can never be defined as a 73macro, and C++'s named operators (see <a href="C_002b_002b-Named-Operators.html#C_002b_002b-Named-Operators">C++ Named Operators</a>) cannot be 74macros when you are compiling C++. 75 76<ul class="menu"> 77<li><a accesskey="1" href="Object_002dlike-Macros.html#Object_002dlike-Macros">Object-like Macros</a> 78<li><a accesskey="2" href="Function_002dlike-Macros.html#Function_002dlike-Macros">Function-like Macros</a> 79<li><a accesskey="3" href="Macro-Arguments.html#Macro-Arguments">Macro Arguments</a> 80<li><a accesskey="4" href="Stringification.html#Stringification">Stringification</a> 81<li><a accesskey="5" href="Concatenation.html#Concatenation">Concatenation</a> 82<li><a accesskey="6" href="Variadic-Macros.html#Variadic-Macros">Variadic Macros</a> 83<li><a accesskey="7" href="Predefined-Macros.html#Predefined-Macros">Predefined Macros</a> 84<li><a accesskey="8" href="Undefining-and-Redefining-Macros.html#Undefining-and-Redefining-Macros">Undefining and Redefining Macros</a> 85<li><a accesskey="9" href="Directives-Within-Macro-Arguments.html#Directives-Within-Macro-Arguments">Directives Within Macro Arguments</a> 86<li><a href="Macro-Pitfalls.html#Macro-Pitfalls">Macro Pitfalls</a> 87</ul> 88 89 </body></html> 90 91