0

I'm trying to use a circular buffer like the one mentioned in this post: https://stackoverflow.com/a/827749

When I need to push and pop things to the buffer I find myself doing something like this all the time:

int data;
int *data_ptr = &data;
cb_pop(spi_buffer, data_ptr);

Is this the best (probably not) way to do this? How would you do it?

Thanks

Community
  • 1
  • 1
evading
  • 3,032
  • 6
  • 37
  • 57
  • 5
    `int data; cb_pop(buffer, &data);` works just as well. No problem with that as long as you understand that `data` is on the current function's stack and goes away as soon as the function returns. – Mat Apr 29 '12 at 13:08

1 Answers1

3

Why won't you just do:

int data;
cb_pop(spi_buffer, &data);

the creation of another pointer variable is redundant.

MByD
  • 135,866
  • 28
  • 264
  • 277