Odd Structure of "for" Loop! - C/C++?

Note: i understand the rest of the code i just do not know exactly how to read the for loop....
1
2
3
4
5
6
7
8
9
10
11
12
13
14

void *memmem(const void *p, const void *q, size_t pn, size_t qn) {

//***** this for loop looks weird, can you explain it please ******//
    for(; pn >= qn; p = (const unsigned char *)p + 1, --pn)
           if(memcmp(p, q, qn) == 0) return p;
    return NULL;

}


void *p;
if((p = memmem(memblock, IpAddrOld, size, sizeof IpAddrOld)) != NULL)
memcpy(p, IpAddrNew, sizeof IpAddrNew);
Last edited on
for(; pn >= qn; p = (const unsigned char *)p + 1, --pn)
the ; means that it isn't initializing anything
pn >= qn; is the condition
p = (const unsigned char *)p + 1, --pn increases the position of 'p' by 1 byte and decreases the value of pn by 1
Topic archived. No new replies allowed.