Skip to main content
Commonmark migration
Source Link

###Macro suggestion###

Macro suggestion

I wanted to quickly suggest something I haven't seen in the other answers. You could use a macro to make your code look nicer:

#define M(m, i, j)    *((m)->matrix + (i)*((m)->rowSize) + (j))

So code like this:

*(result.matrix+ i*r  + j) = *(a->matrix + i*r  + j) + *(b->matrix + i*r  + j);

becomes:

M(&result, i, j) = M(a, i, j) + M(b, i, j);

The advantage of this macro over something like a getElement() function is that you can use M() as an lvalue, whereas getElement() can only be an rvalue.

###Macro suggestion###

I wanted to quickly suggest something I haven't seen in the other answers. You could use a macro to make your code look nicer:

#define M(m, i, j)    *((m)->matrix + (i)*((m)->rowSize) + (j))

So code like this:

*(result.matrix+ i*r  + j) = *(a->matrix + i*r  + j) + *(b->matrix + i*r  + j);

becomes:

M(&result, i, j) = M(a, i, j) + M(b, i, j);

The advantage of this macro over something like a getElement() function is that you can use M() as an lvalue, whereas getElement() can only be an rvalue.

Macro suggestion

I wanted to quickly suggest something I haven't seen in the other answers. You could use a macro to make your code look nicer:

#define M(m, i, j)    *((m)->matrix + (i)*((m)->rowSize) + (j))

So code like this:

*(result.matrix+ i*r  + j) = *(a->matrix + i*r  + j) + *(b->matrix + i*r  + j);

becomes:

M(&result, i, j) = M(a, i, j) + M(b, i, j);

The advantage of this macro over something like a getElement() function is that you can use M() as an lvalue, whereas getElement() can only be an rvalue.

Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

###Macro suggestion###

I wanted to quickly suggest something I haven't seen in the other answers. You could use a macro to make your code look nicer:

#define M(m, i, j)    *((m)->matrix + (i)*((m)->rowSize) + (j))

So code like this:

*(result.matrix+ i*r  + j) = *(a->matrix + i*r  + j) + *(b->matrix + i*r  + j);

becomes:

M(&result, i, j) = M(a, i, j) + M(b, i, j);

The advantage of this macro over something like a getElement() function is that you can use M() as an lvalue, whereas getElement() can only be an rvalue.