Spear and Magic numbers ..
Ahh Toasty. My Boss would be giggling and force a code review on you
Well for safety reasons we've started to head toward
MISRA code process.
One thing is I am not allowed to use 1's or 2's for ANY array reference. I can do something like this
Code:
for(sensor_record_id = sensor_location_first;
sensor_record_id <=sensor_location_last;
sensor_record_id++)
{
printf
(
"%s = [%d]\n",
sensor_name_from_type
(
sensor_get_structure(sensor_record_id)->type_information.type
),
sensor_record_id
);
}
I recomend from now on do NOT use 1 0 2 or any such magic (non enumerated literal type) with anything that references something. It's caused me more stupid mistakes than you can count stars. In my case it could end up someone dying because they might not be warned about something.
So in your case I would suggest
Code:
enum directory_locations {
first_directory_identity,
second_directory_indentity
};
Just to be sure what you are comparing when you read the code looking for why something happened or simply just writting the code, you probably could have caught the woopsie before you spent 5 minutes of debugging

(you saved 5 minutes using literals which you lost in debugging

).
In my case I have a set of pointers to data structures that I've moved from RAM to ROM so that the data structure locations can't be overwritten by some errant bit of code. Reliability and making fewer bugs I've noticed go hand in hand.
I may not be the best at dealing with C++ (Embedded systems mostly use C due to constraints and instantiation issues) but I have had to debug less of my code or see something go wrong.
In C++ I always try to make things as EXPLICITE and OBVIOUS as possible so while I'm writting the code I don't make simple mistakes.
As for my bug... well I was formating floating point data using an sprintf() function to a data buffer. The buffer kept getting trashed because (cough) I didn't range check the floating point buffer before calling sprintf. In this case someone would see
"2349074.1F"
instead of
" 99F 11:04"
WOOPS!
Cyb