This is not so much a question of how to write code, but a matter of coding style. Say I have some code like the following:
Code: Select all
#define TABLE_ADDRESS (void*) 0x00030000
#define TABLE_SIZE 256
static void init_table()
{
domain (*table)[TABLE_SIZE];
uint8_t current_entry;
table = TABLE_ADDRESS;
current_entry = 0;
while (current_entry < TABLE_SIZE)
{
((*table)[current_entry]).name = NULL;
((*table)[current_entry]).format = 0;
((*table)[current_entry]).size = 0;
current_entry += 1;
}
}
So how should I make it so that I can count 256 values in a uint8_t? Using a uint16_t seems a bit wasteful here, but in reality I have to limit the table size to only 255 values. It really seems like I should be able to initialise an array of 256 values using a uint8_t for the counter, but I may be wrong. Am I missing something here, or do I really need to either reduce the table to 255 values or switch to a uint16_t for the counter? If so, which of the latter two would be more acceptable (considering that the size of the table is kind of flexible)?
Thanks,
onlyonemac