static double A[N];
static double *rptr = A; // read ptr
static double *wptr = A; // write ptr
double setdelay(int M) {
rptr = wptr - M;
while (rptr < A) { rptr += N }
}
double delayline(double x)
{
double y;
A[wptr++] = x;
y = A[rptr++];
if ((wptr-A) >= N) { wptr -= N }
if ((rptr-A) >= N) { rptr -= N }
return y;
}
Note separate read- and write-pointers