Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign to itself: optimization or extraneous?

So I was going through the glimg section of the unofficial OpenGL library and came across something I found strange. In one of the functions a pointer parameter is being assigned to itself and I can't see how this could be accomplishing anything. Does this somehow force memory into cache or is it something else? Possibly a bug?

static uint8 *resample_row_generic(uint8 *out, uint8 *in_near, uint8 *in_far, int w, int hs)
{
   // resample with nearest-neighbor
   int i,j;
   in_far = in_far;  // <-- here?
   for (i=0; i < w; ++i)
      for (j=0; j < hs; ++j)
         out[i*hs+j] = in_near[i];
   return out;
}
like image 588
jodag Avatar asked Jan 13 '23 05:01

jodag


1 Answers

It's there to suppress the warning that the parameter in_far is not used in the function.

Another way to suppress the warning is:

(void)in_far;
like image 143
Yu Hao Avatar answered Jan 20 '23 16:01

Yu Hao