c++ - clang 格式的自定义控制语句

标签 c++ c clang clang-format

例如,我们使用宏来检测控制语句

IF (baz == 1) {
    // code
} ELSE {
    // code
}

Clang-format 无法识别这些并且会感到困惑。我注意到有 ForEachMacros,我希望其他控制语句也有类似的东西。

最佳答案

根据您的评论,我已经对此进行了调查:

See here: github.com/dennisguse/ITU-T_stl2009/blob/master/basop/contro‌​l.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/

相关文章:

c - SCNuFAST16 PRIuFAST16 警告 : unknown conversion type character 0x20 in format

c++ - 如何用Cmake获取libasan.so路径?

c++ - 奇怪的 C++ 链接错误

c++ - 类型不完整的唯一指针 - C++2b?

c++ - 平方根和的比较

c++ - 如何丢弃使用 boost::asio 发送的数据?

c++ - C++ 中的共享、弱指针和惰性指针

c++ - 如何在没有 nvcc 的情况下在编译时获取 CUDA 工具包版本?

c++ - C++ 中的图形应用程序和 C 中的代码 **Qt 编程**

C - 编译程序时出现多个警告 "pointer is missing a nullability type specifier",我该怎么办?