diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/SYNTAX/macros.html |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/SYNTAX/macros.html')
-rw-r--r-- | reference/C/SYNTAX/macros.html | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/reference/C/SYNTAX/macros.html b/reference/C/SYNTAX/macros.html new file mode 100644 index 0000000..b7726cf --- /dev/null +++ b/reference/C/SYNTAX/macros.html @@ -0,0 +1,96 @@ +<title>Macros</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Macros</h1> +</center> +<hr> +<p> +Macros are built on the <a href="define_preprocessor.html">#define</a> +preprocessor.<p> +Normally a #define would look like: +<pre> + #define PI 3.142 +</pre> +But, a macro would look like this. +<pre> + #define SQUARE(x) x*x +</pre> +The main difference is that the first example is a constant and the second +is an expression. +If the <b>macro</b> above was used in some code it may look like this: +<pre> + #define SQUARE(x) x*x + + main() + { + int value=3; + printf("%d \n", SQUARE(value)); + } +</pre> +After preprocessing the code would become: +<pre> + main() + { + int value=3; + printf("%d \n", value*value); + } +</pre> +<hr> +<h2>Examples:</h2> + +<a href="../EXAMPLES/macro.c"><img src="../../GRAPHICS/computer.gif"></a> +macro example.<p> +<hr> +<h2>Notes:</h2> +<ul> +<li>The value passed to SQUARE could have been an +<a href="../CONCEPT/data_types.html#int">int</a> +<a href="../CONCEPT/data_types.html#float">float</a> +or +<a href="../CONCEPT/data_types.html#double">double</a> +<li>Long macros can span multiple lines by using a +<a href="../FUNCTIONS/escape.html">\</a> followed by a newline +(return). +<li>If you are using gcc to compile your code, you can use the -E option to +see the preprocessor output +</ul> +<hr> +<h2>See Also:</h2> +<ul> +<li><A href="define_preprocessor.html">#define</a> preprocessor. +<font color=brown> +<li><A href="../../CPLUSPLUS/SYNTAX/inline.html">inline</a> A C++ keyword that provides a better aproch to macros. +</font> +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> |