which field in clang-format to define not to indent after preprocessor directive?

288 Views Asked by At

current codes after applying clang-format is:

#ifndef CEEDLING_TEST
static
#endif
    void
    Measurement(const uint16_t *buff)
{
    g_rmsValue1ms = Get1msRmsValue(buff);

    g_rmsValue60ms = MovingAvgFilter(&g_MaFilter, g_rmsValue1ms);
}

expected:

#ifndef CEEDLING_TEST
static
#endif
void Measurement(const uint16_t *buff)
{
    g_rmsValue1ms = Get1msRmsValue(buff);

    g_rmsValue60ms = MovingAvgFilter(&g_MaFilter, g_rmsValue1ms);
}

Does someone knows which parameter is used to define the behavior like that?

1

There are 1 best solutions below

2
Vojtěch Chvojka On BEST ANSWER

I am not aware of the clang-format option for that.

I'd suggest a small change to your code. Instead of #ifdef-ing the static keyword, you could #ifdef a macro, that decides whether the function is static. This not only resolves issue with clang-format, but also potentially saves you a lot of #ifdef CEEDLING_TESTs and #endifs.

#ifdef CEEDLING_TEST
#define MY_STATIC
#else
#define MY_STATIC static
#endif

MY_STATIC
void Measurement(const uint16_t* buff)
{
    g_rmsValue1ms = Get1msRmsValue(buff);
    g_rmsValue60ms = MovingAvgFilter(&g_MaFilter, g_rmsValue1ms);
}