MISRA 19.4 说明
MISRA 19.4 clarification
我想在我的文件中使用以下宏
#define DO_WAKEUP_SYNCHRONISIEREN proc.id = process_WAKEUP;proc.priority.level = PRIO_AKTIV_1;proc.priority.param=0u;(void)prio_mapF_put_in_matrix(proc)
我知道这违反了 MISRA-C:2004 规则 19.4 - 但我需要使用它来解决违规问题。
有什么方法可以使用 MACRO 并解决 MISRA-C 违规问题吗?
MISRA-C:2004 规则 19.4 是
C macros shall only expand to a braced initialiser, a constant,
a string literal, a parenthesised expression, a type qualifier, a
storage class specifier, or a do-while-zero construct.
看起来规则是:
#define B A
The above is not a permitted form of macro definition under this rule because A is not a constant, braced initializer, parenthesized expression, type qualifier, storage class specifier or do-while-zero construct
#define B (A)
The above is permitted. The replacement list is a parenthesised expression.
这将是一个扩展(即使没有 MISRA 约束,我也会这样做,但我只是注意到规则说明了它:"do-while-zero construct",恕我直言,乍一看 "do-while-zero construct" 表示当您不知道时...):
#define DO_WAKEUP_SYNCHRONISIEREN do {proc.id = process_WAKEUP;proc.priority.level = PRIO_AKTIV_1;proc.priority.param=0u;(void)prio_mapF_put_in_matrix(proc);} while(0)
所以指令块不能"partially called"通过这样的构造:
if (flag) DO_WAKEUP_SYNCHRONISIEREN;
这会让任何试图理解错误的人都头疼。
同时它强制添加一个 ;
而不是简单的 {}
块。所以这个宏看起来很像一个函数调用(也读作Why use do { } while (0) in macro definition?)。
我想在我的文件中使用以下宏
#define DO_WAKEUP_SYNCHRONISIEREN proc.id = process_WAKEUP;proc.priority.level = PRIO_AKTIV_1;proc.priority.param=0u;(void)prio_mapF_put_in_matrix(proc)
我知道这违反了 MISRA-C:2004 规则 19.4 - 但我需要使用它来解决违规问题。
有什么方法可以使用 MACRO 并解决 MISRA-C 违规问题吗?
MISRA-C:2004 规则 19.4 是
C macros shall only expand to a braced initialiser, a constant, a string literal, a parenthesised expression, a type qualifier, a storage class specifier, or a do-while-zero construct.
看起来规则是:
#define B A
The above is not a permitted form of macro definition under this rule because A is not a constant, braced initializer, parenthesized expression, type qualifier, storage class specifier or do-while-zero construct
#define B (A)
The above is permitted. The replacement list is a parenthesised expression.
这将是一个扩展(即使没有 MISRA 约束,我也会这样做,但我只是注意到规则说明了它:"do-while-zero construct",恕我直言,乍一看 "do-while-zero construct" 表示当您不知道时...):
#define DO_WAKEUP_SYNCHRONISIEREN do {proc.id = process_WAKEUP;proc.priority.level = PRIO_AKTIV_1;proc.priority.param=0u;(void)prio_mapF_put_in_matrix(proc);} while(0)
所以指令块不能"partially called"通过这样的构造:
if (flag) DO_WAKEUP_SYNCHRONISIEREN;
这会让任何试图理解错误的人都头疼。
同时它强制添加一个 ;
而不是简单的 {}
块。所以这个宏看起来很像一个函数调用(也读作Why use do { } while (0) in macro definition?)。