c - Proper way to get reference to row in 2D array -


I have tried many times to find the answer to this question but I think I am spoiling my search, But I'm having a hard time taking my head around this time, I think a lot of time away from C. I think.

I have a compilation time that has been declared a 2D buffer:

  uint8_t buffers [NUM_BUFS] [SIZE_BUF];  

Should it be NUM_BUFS size of size SIZE_BUF ? I imagine the NUM_BUFS rows as the SIZE_BUF column.

  •   uint8_t * row = * (buffer +   SIZE_BUF * rowIDX); Uint8_t element = * (line + elementIDX);  

    It compiles precisely and works, but it is cumbersome.

    From the approach of array access:

      uint8_t * row = & amp; Buffers [rowIDX]; Uint8_t element = line [elementIDX];  

    This gives a compiler warning when trying to pass a line in a function trying to reach its elements: Incompatible Pointer Type [enabled by default] Given logic of 'someFunc' 1]]

    And the information statement about it: Expected 'uint8_t *', but logic 'UIT 8_T (*) [515] ] ''

    where someFunc has been declared: some Funk zero (uint8_t * row, uint16_t len);

    I would appreciate some help in doing this, and if there is one there is readability of array brackets.

  • This should work:

      Few functions from zero (uint8_t * Ptr) {}  

    with:

      uint8_t buffers [NUM_BUFS] [SIZE_BUF]; Uint8_t * row = buffers [rowIDX]; Uint8_t element = line [elementIDX]; SomeFunc (line);  

    Comments

    Popular posts from this blog

    sqlite3 - UPDATE a table from the SELECT of another one -

    c# - Showing a SelectedItem's Property -

    javascript - Render HTML after each iteration in loop -