I'm using Eclipse 4.29.0 CDT (STM32CubeIDE) to write C code and have a curious behavior with the auto formatting feature. Arrays with numbers or short element names are formatted as expected (first one) arrays with long initializer names (second one) not. Especially the single element in the beginning of the line is distracting.
#define WHY_AUTOFORMAT_PUT_THIS_HERE 3 //remove this line to change autoformat behavior
uint8_t my_defines_array[] = { NUM1, NUM1, NUM1, NUM3, NUM1, NUM1, NUM3, NUM1, NUM3, NUM1, NUM3, NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM8, NUM8, NUM5,
NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3, NUM8, NUM8, NUM5, NUM1, NUM3 };
uint8_t my_long_names_array[] = { NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3,
WHY_AUTOFORMAT_PUT_THIS_HERE,
NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3, NUM_NUM_NUMBER3 };
My used settings:
Line Wrapping - Expressions - Initializer list:
- Line wrapping only when necessary
- No force split
- Indent on column
Is there a special setting that I'm missing to avoid long names be wrongly formatted?
EDIT:
My minimal example didn't work, but now the behavior is more questionable. The formatting of WHY_AUTOFORMAT_PUT_THIS_HERE
changes depending if it is defined or not.
This issue is that the formatting is wrong when it is defined, not the other way around.
clang-format
for formatting. (I do not useclang
itself). But withclang-format
I got a lot of formatting options (so I can do exactly what I like) and independence from text editors.