Search code examples
ceclipseeclipse-cdtcode-formatting

eclipse cdt formatter is not behaving correctly for bool type in <stdbool.h>


I have ran into a problem with eclipse cdt 3.8.0 formatter on debian. when it formats my code automatically the newline between functions returning bool and block comments is removed like the follow: this a problem in C source files and only applies to bool type please help me correct this problem:

#include <stdbool.h>

/* my comment 1 */
void foo(void);

/* my comment 2 */bool is_valid(void);

/* my comment 3 */
int cool(void);

and I want this:

#include <stdbool.h>

/* my comment 1 */
void foo(void);

/* my comment 2 */
bool is_valid(void);

/* my comment 3 */
int cool(void);

When I comment #include <stdbool.h> and insert the following codes. the formatter act correctly

typedef int bool;
#define true 1
#define false 0

ofcourse when I insert the following codes instead of above code the problem still remains.

#define bool int
#define true 1
#define false 0

It seems that the formmater not acts correctly for Macros


Solution

  • I find a solution, however it is not a complete answer. I noticed that it is a bug for eclipse cdt formatter not understanding bool type. but when I use double slash comments instead of slash star comments the formatter does not join the two lines and since double slash comments are introduced in C99 it will work there.

    /* my comment 1 */
    void foo(void);
    
    // my comment 2
    bool is_valid(void);
    
    /* my comment 3 */
    int cool(void);
    

    of course I think the above problem needs to be reported to the eclipse DEV team. does any one knows where it should be reported?