4 ms·
I think what matters is the intent. Here the intent is to compare against strlen at every turn of the loop. When the compiler is optimizing it might very well
by bombela 5y ago
I think what matters is the intent. Here the intent is to compare against strlen at every turn of the loop.
When the compiler is optimizing it might very well realize that the parameter to strlen doesn't change and the output can be saved first.
If the intent is to compute the length only once, then we can save the length in a variable.
Of course; as others have pointed out; there is no need to call strlen at all in this example.