Search code examples
ceclipsemacroseclipse-cdtcode-formatting

Eclipse CDT macro automatic formatting


I am using TrueSTUDIO 9.1.0 and also tested this within fresh Eclipse IDE for C/C++ developers version: 2018-09 (4.9.0).

Automatic code formatter seems to be putting semicolon after a macro call on a new line.

Steps to reproduce:

  1. Download Eclipse IDE for C/C++ developers version: 2018-09 (4.9.0) for Windows 32bit.

  2. Create new empty C project

  3. Create .c file with code:

    #define testmacro() do {printf("test");} while (0)

    void main(void) { testmacro(); }

  4. Format the whole file by pressing Ctrl+Shift+F

  5. Get:

    #define testmacro() do {printf("test");} while (0)
    void main(void) { testmacro() ; }

It was discussed and dismissed in this question (link) for the reason that it was fixed.

Am I doing something wrong or did the error come back?


Solution

  • I don't think you're doing anything wrong, the CDT built-in formatter is just buggy and unmaintained. There are dozens of open bugs about its behaviour. In this case, it looks like bug 475349.

    I would recommend using a plugin that wraps a modern, maintained formatter like clang-format, such as CppStyle.