In C, what is the difference between static const and const inside a function?
For instance, take the given code examples:
void print_int(int x) {
assert( x < 5 && x > -5 );
const int i[9] = {
-4, -3, -2, -1, 0, 1, 2, 3, 4
};
printf("%i", i[x + 4]);
}
int main() {
print_int( 1 );
return 0;
}
Versus:
void print_int(int x) {
assert( x < 5 && x > -5 );
static const int i[9] = {
-4, -3, -2, -1, 0, 1, 2, 3, 4
};
printf("%i", i[x + 4]);
}
int main() {
print_int(1);
return 0;
}
Would the generated assembly be optimized better if I used static const instead of const, or would the output be the same for both examples?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire