How to more correctly describe the cycle for the following code scheme:

int len = size of ebytes; int tlen = 0; uchar *ebytes = ...входящий буфер данных; uchar *obytes = ...из ходящий буфер данных; uchar *ubuf = calloc(1,256); /// вот тут сложности понимания #pragma omp parallel private(tlen) schedule(dynamic) reduction(+:ebytes) reduction(+:obytes) do { int sz = 256; memcpy((void*)ubuf, (void*)ebytes, sz); ebytes += sz; tlen += sz; func (ubuf, &sz); memcpy((void*)obytes, (void*)ubuf, sz); obytes += sz; } while (len > tlen); 

with for loops like everything is more or less clear, but I don’t really want to go over to the loop for ideological reasons.

Seems to have to redo it.

  • In each cycle, you define an object sz and keep the object tlen in total visibility. It is better, of course, in the for loop to define sz once and tlen increase from .. to. So the question is: why do we need an explicit cast in void * in memcpy ((void *) ubuf, (void *) ebytes, sz) ;? You can just memcpy ((ubuf, ebytes, sz); - AR Hovsepyan
  • sz changes to func() , the cast is superfluous, I agree, but it’s not the point. And I understand that you can't do without for ? And I have doubts, will ubuf be unique for each iteration? given that the memory for it is allocated once above the cycle? - NewView

0