clang-format 如何缩进 c++ 中的 pragma?
黄舟
黄舟 2017-04-17 12:00:08
0
2
789

比如,

cpp#include <omp.h>
#include <cstdio>
int main()
{
#pragma omp parallel for
    for (int i = 0; i < 10; ++i)
    {
        puts("demo");
    }
    return 0;
}

希望用 clang-format 格式化成:

cpp#include <omp.h>
#include <cstdio>
int main()
{
    #pragma omp parallel for
    for (int i = 0; i < 10; ++i)
    {
        puts("demo");
    }
    return 0;
}
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
迷茫

Clang-format is not currently supported.

For this somewhat special formatting requirement, clang-format provides a one-size-fits-all solution:

cpp#include <omp.h>
#include <cstdio>
int main() {
// clang-format off
  #pragma omp parallel for
  // clang-format on
  for (int i = 0; i < 10; ++i) {
    puts("demo");
  }
  return 0;
}

As shown above, between the // clang-format off and // clang-format on switches, you can keep whatever format you want, clang-format does not matter.

阿神

You won’t have to worry if you write this way

#include <omp.h>
#include <cstdio>
int main()
{
#   pragma omp parallel for
    ...
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!