Here you assign a dram_controller_maximum
to 10, which simply means that each time you write
something = dram_controller_maximum
, you mean something = 10
:
enum DRAM_Controller { dram_controller_maximum = 10};
For the following function, if you pass it a number, it will just print it. If you pass a DRAM_Controller
variable, it will evaluate it's value (a number, remember), and print it.
void myprint(DRAM_Controller dct)
{
printf("dct value is: %d\n", dct);
}
The following line just transforms the integer (0
) to DRAM_Controller
. This line alone is pretty useless:
DRAM_Controller(0); //**--> What is the meaing of this**
The next three lines will print the dram_controller_maximum
value converted to int. Remember, in the beginning we said it's equal to 10, so this will just print 10. All the three lines do the same thing: they try to interpret the DRAM_Controller-type value as an int and print it:
printf("value is : %d\n", dram_controller_maximum);
printf("value is : %d\n", DRAM_Controller(1));
myprint(DRAM_Controller(0));
Basically, an enum
is just a bunch of int
s that have "names":
C exposes the integer representation of enumeration values directly to
the programmer. Integers and enum values can be mixed freely, and all
arithmetic operations on enum values are permitted. It is even
possible for an enum variable to hold an integer that does not
represent any of the enumeration values. In fact, according to the
language definition, the above code will define CLUBS, DIAMONDS,
HEARTS, and SPADES as constants of type int, which will only be
converted (silently) to enum cardsuit if they are stored in a variable
of that type
and
C++ has enumeration types that are directly inherited from C's and
work mostly like these, except that an enumeration is a real type in
C++, giving additional compile-time checking.
from wiki.