例如,我们使用宏来检测控制语句
IF (baz == 1) {
// code
} ELSE {
// code
}
Clang-format 无法识别这些并且会感到困惑。我注意到有 ForEachMacros
,我希望其他控制语句也有类似的东西。
最佳答案
根据您的评论,我已经对此进行了调查:
See here: github.com/dennisguse/ITU-T_stl2009/blob/master/basop/control.h
您需要 #include <control.h>
在您的项目中,以便定义宏。
在那之后,看起来你应该可以做到 #undef WMOPS
,一切都会恢复到“正常”。
这些宏似乎用于分析/分析软件的操作——重要的是每个for
出现了多少次| , while
, do
, if
, else
, switch
, continue
, break
, goto
在特定的执行区域中使用。
参见 g722/decg722.c:446
和 :494
:
if(header[0] != G192_SYNC){ /* bad frame, (with zero length or valid G.722 length) */
/* ... */
} else { /* good frame, update index memory mem_code and mode memory mem_mode */
#ifdef WMOPS
setCounter(spe2Id);
fwc();
Reset_WMOPS_counter();
#endif
然后 :567
:
#ifdef WMOPS
setCounter(spe1Id);
fwc();
WMOPS_output(0);
setCounter(spe2Id);
fwc();
WMOPS_output(0);
#endif
currCounter
变量设置在 setCounter()
内... 这里计数器被选中并在 G192_SYNC
上重置,然后计算信息,并在接收到帧后输出。
我做了一个简单的版本来演示:
#include <stdio.h>
#ifndef WMOPS
#define FOR(a) for(a)
#else /* WMOPS */
#define FOR(a) \
if (incrFor(), 0); else for(a)
int myFor = 0;
static __inline void incrFor(void) {
myFor++;
}
#endif /* WMOPS */
void t(int x) {
int i;
FOR (i = 0; i < 5; i++) {
printf("x: %d i: %d\n", x, i);
}
}
int main(void) {
t(1);
t(2);
#ifdef WMOPS
printf("myFor: %d\n", myFor);
#endif
return 0;
}
$ gcc wm.c -o wm && ./wm
x: 1 i: 0
x: 1 i: 1
x: 1 i: 2
x: 1 i: 3
x: 1 i: 4
x: 2 i: 0
x: 2 i: 1
x: 2 i: 2
x: 2 i: 3
x: 2 i: 4
$ gcc wm.c -o wm -DWMOPS && ./wm
x: 1 i: 0
x: 1 i: 1
x: 1 i: 2
x: 1 i: 3
x: 1 i: 4
x: 2 i: 0
x: 2 i: 1
x: 2 i: 2
x: 2 i: 3
x: 2 i: 4
myFor: 2
关于c++ - clang 格式的自定义控制语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43209173/