Quote Originally Posted by Nikosant03 View Post
I have a lot of questions but let's start from a simple one


Why you use anonymous enum instead of:
Code:
#define NUM_FLEXIFORCE_SENSORS 8 // OR
const uint8_t num_flexiforce_sensors = 8;
Like a lot of things, it's mainly from habit. ;-)

I don't use variables (such as const uint8_t num_flexiforce_sensors = 8;) because they are variables, not constants. You cannot use a variable to size an array at all in pre-VLA versions of C, and even after VLAs there are restrictions on where they can be used. File scope is right out.

I prefer enums over preprocessor symbols because historically, using enum created entries in debug records, and because enums could be types, which made it possible for the compiler to warn you if you made certain kinds of mistakes. (Not relevant in this situation, since I was just using the enum to get a named constant.)

The part about enums creating debug records is important because if you see a value in memory, or in a register, and the value is "17" it doesn't tell you anything. "errno is 17, I wonder what that is?" Whereas, if you can get the debugger or dumper to show you "errno = EEXIST" that saves a lot of time and curiousity.