1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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>
|