Skip to main content
Code Review

Return to Revisions

2 of 2
Commonmark migration

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.

JS1
  • 28.8k
  • 3
  • 41
  • 83
default

AltStyle によって変換されたページ (->オリジナル) /