eclipse cdt formatter对于<stdbool.h>中的bool类型行为不正确</stdbool.h>

时间:2014-10-30 07:13:00

标签: c eclipse eclipse-cdt code-formatting

我在debian上遇到了eclipse cdt 3.8.0 formatter的问题。当它自动格式化我的代码时,返回bool和块注释的函数之间的换行符将被删除,如下所示: 这是C源文件中的问题,仅适用于bool类型 请帮我纠正这个问题:

#include <stdbool.h>

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

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

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

我想要这个:

#include <stdbool.h>

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

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

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

当我评论#include <stdbool.h>并插入以下代码时。格式化程序正确行事

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

当我插入以下代码而不是上面的代码时,问题仍然存在。

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

似乎格式化程序无法正确处理宏

3 个答案:

答案 0 :(得分:4)

我找到了解决方案,但这不是一个完整的答案。 我注意到这是eclipse cdt格式化程序不能理解bool类型的错误。 但是当我使用双斜杠注释而不是斜线星注释时,格式化程序不会加入这两行,因为在C99中引入了双斜杠注释,它将在那里工作。

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

// my comment 2
bool is_valid(void);

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

当然我认为上述问题需要向Eclipse DEV团队报告。是否有人知道应该在哪里报告?

答案 1 :(得分:0)

我无法在eclipse的菜单中找到任何允许您为函数原型配置换行的条目。

我只建议您在日食中使用搜索和替换,选择要编辑的所有行,按CTRL + F,在搜索字段中使用*/填充搜索对话框,然后{{1}在替换字段中,检查&#39;正则表达式&#39;框,然后单击全部替换。

答案 2 :(得分:0)

旧线程,但我遇到了与c99 bool和stdbool.h相关的类似问题。 cdt项目设置默认包含__cplusplus宏的定义,stdbool.h使用该定义来定义bool / true / {{1}如果代码是C ++。只需删除项目属性中的&#34; C / C ++包含路径和预处理器符号&#34;。