1

I'm using clang-format 10.0 and I'm trying to get a designated initializer function macro to get formatted and I can't seem to get it working. My structures are formatted as intended, looking along the lines of

struct_type foo = { 
   .bar1 = x,
   .bar2 = y,
}

Here comes the tricky part that doesn't work. To initialize some of these structures with default values, I'm using macros that look like this:

#define STRUCT_TYPE_FOO_DEFAULT() { \
   .bar1 = x_default,               \
   .bar2 = y_default,               \
}                          

For some reason, those macros are always getting formatted looking like this:

#define STRUCT_TYPE_FOO_DEFAULT()         \
{                                         \
    .bar1 = x_default, .bar2 = y_default, \
}   

What options should I modify to get the desired result?

Gerhardh
  • 11,688
  • 4
  • 17
  • 39
hunterzz
  • 46
  • 3
  • please paste some code where you actually use the `STRUCT_TYPE_FOO_DEFAULT` macro, and tell how it fails – tstanisl Mar 10 '21 at 10:58
  • 1
    @tstanisl: The question is not about code failing in compilation or execution. It is about the `clang-format` program, which formats source code, not formatting code in the desired way. – Eric Postpischil Mar 10 '21 at 11:06
  • 1
    @tstanisl: Seven minutes before you entered your answer, you were informed that this question is not about compilation (including preprocessing). Then you entered an answer about how macros are replaced. That is not what this question is about. `clang-format` is a program that reformats source code to “look nice”. It adjusts the indentation, position, and formatting of braces, bodies of loops, continuation lines of macros, and so on. OP is asking for settings to make `clang-format` format their macro as desired, not to control its preprocessing replacement. – Eric Postpischil Mar 10 '21 at 13:08
  • 2
    Unfortunately, I'm not aware of any clang-format options for controlling this. A quick look through the style options documentation doesn't reveal anything new. I'll follow this question because now I'm genuinely curious if this is possible, or it is yet another clang-format limitation. – icebp Mar 10 '21 at 16:22
  • 1
    If I manage to find a workaround, I'll update this. Apologies for the formulation, I know it's subpar, but this was the best way I could put it. – hunterzz Mar 11 '21 at 09:35
  • Maybe someone on the [llvm discord](https://discord.com/invite/xS7Z362) could help you? I think clang-format needs to be extended in some way in order to be able to control this. – icebp Mar 11 '21 at 11:22

0 Answers0