为什么Eclipse CDT的说:“语法错误”,但编译没有问题 [英] Why does Eclipse CDT say: 'syntax error', but compilation no problem

查看:1900
本文介绍了为什么Eclipse CDT的说:“语法错误”,但编译没有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在现有的C code具有与类似这样的语句几行工作

I am working in existing C code which has a couple of lines with statements similar to this one:

struct collect_conn *tc = (struct collect_conn *) 
     ((char *)c - offsetof(struct collect_conn, runicast_conn));

该结构collect_conn大意如下云:

The struct collect_conn goes along the following lines:

struct collect_conn {
  struct runicast_conn runicast_conn;
  struct announcement announcement;
  const struct collect_callbacks *cb;
  struct ctimer t;
  uint16_t rtmetric;
  uint8_t forwarding;
  uint8_t seqno;
};

我使用Eclipse CDT的,它标志着一个橙色的波浪线为语法错误行。我认为它是由CDT索引标记。
然而,汇编(手动在终端)是没有问题的。

I am using Eclipse CDT, and it marks the line with an orange squiggly line as 'syntax error'. I think it is marked as such by the CDT indexer. However, compilation (manually in a terminal) is no problem.

这是一个有点不方便,但是由于上线的元素不被索引(所以调用层次结构树并不总是正确,或者元素的高亮,等等。)

This is a bit inconvenient however, since the elements on the line don't get indexed (so the call hierarchy tree isn't always correct, or the highlighting of elements, etc.)

为什么的Ecipse不喜欢就行,因为它是?

Why does Ecipse not like the line as it is?

推荐答案

Eclipse CDT的包含它自己的preprocessor ​​/分析您的code和建立索引解析器。然而,当你调用构建CDT召唤出你的系统编译器GCC一样,例如。有可能是由CDT解析器和你的编译器所接受的语法接受的语法之间的细微差别。当发生这种情况CDT解析器可以得到混淆。

Eclipse CDT contains its own preprocessor/parser for analyzing your code and building an index. However, when you invoke a build CDT calls out to your system compiler, like gcc for example. There may be minor differences between the syntax accepted by the CDT parser and the syntax accepted by your compiler. When this happens the CDT parser can get confused.

在我的系统 offsetof 宏扩展到使用 __ offsetof __ 关键字的前pression。所以这就是为什么有一个语法错误此关键字不被认可的CDT。为了解决这个问题,CDT解析器宏建在处理 __ __ offsetof 看起来像这样:

On my system the offsetof macro expands into an expression that uses the __offsetof__ keyword. This keyword isn't recognized by CDT so that's why there's a syntax error. To deal with this problem the CDT parser has a macro built in to deal with __offsetof__ which looks like this:

#define __offsetof__(x) (x)

这并不似乎是正确的,至少在我的系统上的结果是offsetof __ 去除 __的关键字从中仍然会导致语法错误的来源。

This doesn't appear to be correct, at least on my system the result is the removal of the __offsetof__ keyword from the source which still leads to a syntax error.

我能够通过进入路径和符号属性页并添加 __ offsetof __ 宏映射到'富'摆脱语法错误。这个招数解析器以为它只是调用它之前没有见过的功能,但不是一个语法错误。

I was able to get rid of the syntax error by going to the Paths and Symbols property page and adding a macro for __offsetof__ which maps to 'foo'. This tricks the parser into thinking its just a call to a function it hasn't seen before, but not a syntax error.

另外,您可以通过转到窗口> preferences>常规>编辑>文本编辑器>注释和取消选中所有复选框对C关闭语法错误报告在编辑器/ C ++索引标记。

Alternatively you can turn off syntax error reporting in the editor by going to Window > Preferences > General > Editors > Text Editors > Annotations and unchecking all the checkboxes for C/C++ Indexer Markers.

这篇关于为什么Eclipse CDT的说:“语法错误”,但编译没有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆