3 ms·
As others have noted, this is a little bizarre as the two functions are doing different things; one being less performant than the other is not really surprisin
by mnarayan01 9y ago
As others have noted, this is a little bizarre as the two functions are doing different things; one being less performant than the other is not really surprising. That said, there can be advantages to using array syntax rather than pointers for strings (even when also declaring the pointer to be constant), e.g. the compiler "knows" the array "pointer" is non-null:
extern const char arr[];
void do_arr() {
if (arr) {
dummy();
}
}
allows the compiler to optimize out the conditional: https://godbolt.org/g/FwBeWx https://godbolt.org/g/FwBeWx.