1

如果不滚动,我的宏不能很好地适应屏幕,所以我想把它分解,这样它读起来很好。如果它看起来像这样,它可以正常工作:

#define longMacro(ptr, idx0, idx1, idx2, idx3, idx4, dim1, dim2, dim3, dim4) (*((ptr) + (idx0) * (dim1) * (dim2) * (dim3) * (dim4) + (idx1) * (dim2) * (dim3) * (dim4) + (idx2) * (dim3) * (dim4) + (idx3) * (dim4) + (idx4)))

但是当我尝试像这样分解它时:

#define longMacro(ptr, idx0, idx1, idx2, idx3, idx4, dim1, dim2, dim3, dim4) 
    (*((ptr) + (idx0) * (dim1) * (dim2) * (dim3) * (dim4) 
    + (idx1) * (dim2) * (dim3) * (dim4) + (idx2) * (dim3) * (dim4) 
    + (idx3) * (dim4) + (idx4)))

我收到这些错误

错误:在 '+' 标记之前需要 `)'
错误:在 '+' 标记之前
需要 `)' 错误:在 '+' 标记之前需要 `)'
错误:在 '+' 标记之前需要 `)'

4

1 回答 1

2

我认为您在每行末尾缺少一个“\”

#define longMacro(ptr, idx0, idx1, idx2, idx3, idx4, dim1, dim2, dim3, dim4) \
    (*((ptr) + (idx0) * (dim1) * (dim2) * (dim3) * (dim4) \
    + (idx1) * (dim2) * (dim3) * (dim4) + (idx2) * (dim3) * (dim4) \
    + (idx3) * (dim4) + (idx4)))
于 2012-10-12T14:43:55.387 回答