简体   繁体   中英

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

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?

I couldn't find any entry in eclipse's menu that allow you to configure line wrapping for function prototypes.

I can only suggest you to use the search and replace within the eclipse, select all lines you want to edit, press CTRL+F, fill the search dialog with */ in the search field and */\\n in the replace field, check the 'regular expressions' box and click replace all.

Old thread, but I ran into a similar problem related to the c99 bool and stdbool.h . The cdt project settings have a definition for the __cplusplus macro by default, which is used by stdbool.h to NOT define bool / true / false if the code is C++. Just delete that in project properties under "C/C++ Include Paths and Preprocessor Symbols".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM