☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

宏的实参个数不可大于形参个数

3.3.3 ID_macro_redundantArgs
目录 › next › previous

宏的实参个数大于形参个数是不符合 C/C++ 标准的,多余的宏参数是没有意义的,然而在某些编译环境下却可以通过编译。

示例:

#define M(a, b, c)  a ## b ## c

const char* foo() {
    return M("a", "b", "c", "d");  // Non-compliant
}

例外:

#define MSG(fmt, ...) printf(fmt, __VA_ARGS__)

int main() {
    MSG("%d %d\n", 1, 2);  // Compliant
}

可变宏参数列表可不受本规则约束。

相关

ID_macro_insufficientArgs

依据

ISO/IEC 9899:1999 6.10.3(4) ISO/IEC 9899:2011 6.10.3(4) ISO/IEC 14882:2003 16.3(4) ISO/IEC 14882:2011 16.3(4)

参考

CWE-628
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.