Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Code Formatter Indentation(Code Formatter Indentation appears to to be inconsistent)
Code Formatter Indentation [message #1816276] Fri, 25 October 2019 03:14
Eclipse UserFriend
Applying the code formatter to my example code, the result is as follows:
#define reg_bit_a_pos (3)
#define reg_bit_b_pos (7)
#define reg_bit_c_pos (10)

#define reg_flag(pos) (1 << pos)

void func(void)
{
    volatile void *reg = 0x12345678;

    reg |=
    reg_flag(reg_bit_a_pos) |
        reg_flag(reg_bit_a_pos) |
        reg_flag(reg_bit_c_pos);

    reg |=
        1 << reg_bit_a_pos |
            1 << reg_bit_b_pos |
            1 << reg_bit_c_pos;

    reg |=
        (1 << reg_bit_a_pos) |
            (1 << reg_bit_b_pos) |
            (1 << reg_bit_c_pos);

    reg |=
        0x00000004 |
            0x00000080 |
            0x00000800;
}

The result I am trying to achieve is:

    reg |=
        reg_flag(reg_bit_a_pos) |
        reg_flag(reg_bit_a_pos) |
        reg_flag(reg_bit_c_pos);

    reg |=
        1 << reg_bit_a_pos |
        1 << reg_bit_b_pos |
        1 << reg_bit_c_pos;

    reg |=
        (1 << reg_bit_a_pos) |
        (1 << reg_bit_b_pos) |
        (1 << reg_bit_c_pos);

    reg |=
        0x00000004 |
        0x00000080 |
        0x00000800;

This leaves me with two issues that I cannot seem to resolve by modifying the formatter settings.

1. Why the macro line 'reg_flag(reg_bit_a_pos)' indents differently from non-macro version '1 << reg_bit_a_pos'?

2. How to stop the second level indentation, i.e. how to ensure that '1 << reg_bit_b_pos' (and all subsequent lines) to have the same indentation as '1 << reg_bit_a_pos'?

The Eclipse version is Eclipse IDE for C/C++ Developers, Version: 2019-09 R (4.13.0), Build id: 20190917-1200, fresh download and no plug-ins.

I am assuming that I'm too stupid to setup the formatter, so I have exported and attached my formatter setup.

Any help would be greatly appreciated.
Previous Topic:Upgrade Confusion
Next Topic:Unable to launch Eclipse in Ubuntu 18.04 post-installation
Goto Forum:
  


Current Time: Tue Jun 24 22:54:54 EDT 2025

Powered by FUDForum. Page generated in 0.02824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top