S
skibud2
Consider this example:
u8 my_array[10];
for (i = 0; i < (sizeof(my_array)/sizeof(u8)); i++) {
...
}
In the standard C specification, is the evaluation of
'(sizeof(my_array)/sizeof(u8))' to 10 guarenteed to happen at compile
time? Or is it a compiler optimization? From what I have read, it
looks like it is a compiler optimization, but I would like to get
confirmation.
Now if is not guarenteed to happen at compile time, is it better to do
something like the following:
const u8 my_array_size = (sizeof(my_array)/sizeof(u8));
to guarentee that you are not doing a divide a run time? On the
systems I have worked on, divides take a very long time. However,
almost every compiler that I have dealt with does the evaluation at
compile time.
u8 my_array[10];
for (i = 0; i < (sizeof(my_array)/sizeof(u8)); i++) {
...
}
In the standard C specification, is the evaluation of
'(sizeof(my_array)/sizeof(u8))' to 10 guarenteed to happen at compile
time? Or is it a compiler optimization? From what I have read, it
looks like it is a compiler optimization, but I would like to get
confirmation.
Now if is not guarenteed to happen at compile time, is it better to do
something like the following:
const u8 my_array_size = (sizeof(my_array)/sizeof(u8));
to guarentee that you are not doing a divide a run time? On the
systems I have worked on, divides take a very long time. However,
almost every compiler that I have dealt with does the evaluation at
compile time.