CATEGORII DOCUMENTE |
Asp | Autocad | C | Dot net | Excel | Fox pro | Html | Java |
Linux | Mathcad | Photoshop | Php | Sql | Visual studio | Windows | Xml |
These fall into the category of 'half baked'. They aren't proper enumerated
types, as in Pascal, and only really serve to help you reduce the number of #define
statements in your program. They
look like this:
Just as with structures and unions, the e_tag
is the tag, and var
is the
definition of a variable.
The names declared inside the enumeration are constants with int
type. Their values are these:
so you can see that, in the absence of anything to the contrary, the values assigned start at zero and increase. A specific value can be given if you want, when the increase will continue one at a time afterwards; the specific value must be an integral constant (see later) that is representable in an int. It is possible for more than one of the names to have the same value.
The only use for these things is to give a better-scoped version of this:
#define a 0It's better scoped because the declaration of enumerations follows the
standard scope rules for C, whereas #define
statements have file scope.
Not that you are likely to care, but the Standard states that enumeration types are of a type that is compatible with an implementation-defined one of the integral types. So what? For interest's sake here is an illustration:
enum eee_var, *ep;The names a
,
b
, and c
all behave as if they were int
constants when you use them; e_var
has type enum ee
and ep
is a pointer to enum ee
. The compatibility requirement means
that (amongst other implications) there will be an integral type whose address
can be assigned to ep
without violating the type-compatibility requirements for pointers.
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 703
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved