http://www.nongnu.org/avr-libc/user-manual/FAQ.html
What registers are used by the C compiler?
* Data types:
char is 8 bits, int is 16 bits, long is 32 bits, long long is 64
bits, float and double are 32 bits (this is the only supported floating
point format), pointers are 16 bits (function pointers are word
addresses, to allow addressing up to 128K program memory space). There
is a -mint8 option (see Options for the C compiler avr-gcc) to make int
8 bits, but that is not supported by avr-libc and violates C standards
(int must be at least 16 bits). It may be removed in a future release.
http://msdn.microsoft.com/en-us/library/whbyts4t(v=vs.80).aspx
"In ANSI C, the expressions that define the value of an enumerator
constant always have int type; thus, the storage associated with an
enumeration variable is the storage required for a single int value. An
enumeration constant or a value of enumerated type can be used anywhere
the C language permits an integer expression."
=>
1 | enum ReqCodes {REQUEST=1, REPEAT=8, RESET=127};
|
2 |
|
3 | union TxArrayWortConverter {
|
4 | int16_t WortArray[TelLen];
|
5 | struct ReqTel {
|
6 | uint16_t Command; // <====
|
7 | ...
|
8 | } Einzelwert;
|
9 | } DatTxBuf;
|
beissen sich. Z.B. eine Abfrage wäre ein Cast Gewurschtel
1 | if( (( enum ReqCodes ) DatTxBuf.Einzelwert.Command) == RESET ) {
|
Alternative:
1 | union TxArrayWortConverter {
|
2 | int16_t WortArray[TelLen];
|
3 | struct ReqTel {
|
4 | enum ReqCodes Command; // <====
|
5 | ...
|
6 | } Einzelwert;
|
7 | } DatTxBuf;
|
8 |
|
9 | // =>
|
10 |
|
11 | if( DatTxBuf.Einzelwert.Command == RESET ) {
|
> Besser ohne enum mit einem define?
Googel mal nach "difference enum define macro", Vor- und Nachteile
werden da genannt.