Fujitsu microcontroller used is 32bit. Hence enum storage is also 32bit. But in my project actually enum elements do not exceed more than 256. Is there any compiler options to size down the storage for enums?
Asked
Active
Viewed 247 times
2 Answers
1
You could use a bit field to be able to store 256 unique values in 8 words (256 bits / 32 bit words = 8), but then the compiler will no longer be able to enforce that only a single bit is set at a time. But, you could easily write a wrapper function to clear out all the previous bits before setting one. It would probably end up kind of messy, but that's what tends to happen when you start using these kinds of tricks at this level to save memory.

Mark Rushakoff
- 249,864
- 45
- 407
- 398
0
You could use preprocessor macros (#define) to map symbolic names to values. without knowing what your application is, it's hard to predict if this is sensible :)

XTL
- 851
- 1
- 8
- 23