0
我在C定義這樣一個宏功能:C近拍功能錯誤
#define NUM_FROM_DENSE_MAT (PTR, II, JJ, RROW) ((PTR[JJ * RROW + II]))
我稱爲如下:
/*io.h:141*/ float num = NUM_FROM_DENSE_MAT(p_mat->p_val_host, i, j, p_mat->row);
凡p_mat->p_val_host
是float陣列,並且所有其它的是整型數字。
但是,當我complie它,我得到了以下錯誤:
io.h(141): error: identifier "PTR" is undefined
io.h(141): error: identifier "II" is undefined
io.h(141): error: identifier "JJ" is undefined
io.h(141): error: identifier "RROW" is undefined
如果它不被翻譯成p_mat->p_val_host[j * p_mat->row + i]
?
對此使用類似函數的宏是一個非常糟糕的主意。你所做的只是創建混淆和不安全的代碼,沒有收穫。 – Lundin 2013-04-05 14:06:45