Yes, there is a difference in their behavior. They both perform the same number of iterations, but the value of l1 when the loop terminates will differ.
Code:
$ cat while.c
#include <stdio.h>
int main(void)
{
int l1, l2, iter;
l1 = 5;
l2 = 2;
iter = 0;
printf("Starting decrement in loop body with l1 = %d, l2 = %d\n", l1, l2);
while (l1 >= l2) {
l1--;
printf("iteration %d\n", ++iter);
}
printf("Finishing with l1 = %d, l2 = %d\n", l1, l2);
l1 = 5;
l2 = 2;
iter = 0;
printf("Starting decrement in loop condition with l1 = %d, l2 = %d\n", l1, l2);
while (l1-- >= l2) {
printf("iteration %d\n", ++iter);
}
printf("Finishing with l1 = %d, l2 = %d\n", l1, l2);
return 0;
}
$ make while
gcc -Wall -ggdb3 -std=c99 -O0 -o while while.c -lm -lpthread -lrt
$ ./while
Starting decrement in loop body with l1 = 5, l2 = 2
iteration 1
iteration 2
iteration 3
iteration 4
Finishing with l1 = 1, l2 = 2
Starting decrement in loop condition with l1 = 5, l2 = 2
iteration 1
iteration 2
iteration 3
iteration 4
Finishing with l1 = 0, l2 = 2
With the decrement inside the loop body, l1 only decrements when the loop condition is true, meaning it doesn't decrement when l1 becomes small enough to cause the loop to stop. With the decrement in the loop condition, however, l1 decrements every time the loop condition is checked, which is every time the condition is true and when the condition is checked and fails. Thus, putting l1-- in the loop condition will leave l1 with a value 1 less than it would if the decrement is in the loop body.
Now, for that implementation of strstr that you referenced, it doesn't really matter, since the value of l1 is not used after the loop. But in general, such loops are not equivalent.