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/enum.html |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/SYNTAX/enum.html')
-rw-r--r-- | reference/C/SYNTAX/enum.html | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/reference/C/SYNTAX/enum.html b/reference/C/SYNTAX/enum.html new file mode 100644 index 0000000..8f6b393 --- /dev/null +++ b/reference/C/SYNTAX/enum.html @@ -0,0 +1,97 @@ +<title>The enum statement</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The enum statement</h1> +</center> +<hr> +<p> +ENUM is closely related to the <a href="define_preprocessor.html">#define</a> +preprocessor.<p> +It allows you to define a list of aliases which represent integer numbers. For +example if you find yourself coding something like: +<pre> + #define MON 1 + #define TUE 2 + #define WED 3 +</pre> +You could use <b>enum</b> as below. +<pre> + enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days; + or + enum escapes { BELL = '\a', BACKSPACE = '\b', HTAB = '\t', + RETURN = '\r', NEWLINE = '\n', VTAB = '\v' }; + + or + enum boolean { FALSE = 0, TRUE }; + +</pre> + +An advantage of <b>enum</b> over <b>#define</b> is that it has +<a href="../glossary.html#scope">scope</a> +This means that the variable (just like any other) is only visable +within the block it was declared within. +<p> +<hr> +<h2>Notes:</h2> +<ul> +<li>If a variable is +<a href="../glossary.html#definition">defined</a> +with <b>enum</b> it is considered by +the compiler to be an integer, and can have ANY integer value assigned +to it, it is not restericted to the values in the enum statement. +</ul> + + +<hr> +<h2>See Also:</h2> + +<a href=../../CPLUSPLUS/SYNTAX/enum.html> C++ Enhancements to enum.</a><p> +<a href=define_preprocessor.html>#define</a> preprocessor.<p> + +<hr> +<h2>Examples:</h2> + +<a href="../EXAMPLES/enum1.c"><img src="../../GRAPHICS/computer.gif"></a> +enum example 1.<p> +<a href="../EXAMPLES/enum2.c"><img src="../../GRAPHICS/computer.gif"></a> +enum example 2.<p> + +<a href="../EXAMPLES/enum3.c"><img src="../../GRAPHICS/computer.gif"></a> +enum coding error.<p> + +<a href="../EXAMPLES/enum4.c"><img src="../../GRAPHICS/computer.gif"></a> +Another enum coding error.<p> + +<a href="../EXAMPLES/enum5.c"><img src="../../GRAPHICS/computer.gif"></a> +enum and #define coding error.<p> + +<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> |