Visual Studio Code 抱怨关于结构属性语法。

huangapple go评论117阅读模式
英文:

Visual Studio Code complaining about struct attribute syntax

问题

在以下代码片段(用于 ARM 嵌入式芯片的 C 代码)中,

```c
typedef struct __attribute__((__packed__)) MyStruct_S
{
    int MyFirstField;
    int MySecondField;
} MyStruct_Type;

VS Code 对 MyStruct_S 标识符之后的属性发出投诉。投诉内容为"expected a ';'C/C++(65)"。

然而,即使设置了 -Wall 和 -Wextra 编译器标志,这段代码仍然可以编译并正常运行。

VS Code 做错了什么? 我们可以修复 IntelliSence 以识别这是正确的语法吗?

我在此工作区中安装的扩展如下:

  • Arm Assembly
  • C/C++
  • Doxygen Documentation Generator
  • GNU Linker Map files
  • Makefile Tools
  • WSL

祝好!


<details>
<summary>英文:</summary>

In the following code snippet (C, for ARM embedded chips)

typedef struct attribute((packed)) MyStruct_S
{
int MyFirstField;
int MySecondField;
} MyStruct_Type;


VS Code complains on the MyStruct_S identifier, following the attribute. The complaint says &quot;expected a &#39;;&#39;C/C++(65)&quot;.

And yet this code compiles and runs just fine even with -Wall and -Wextra compiler flags set. 

**What is VS Code doing wrong?** Can we fix the IntelliSence to see that this is correct syntax?


The extensions I have for this workspace are the following:

 - Arm Assembly
 - C/C++
 - Doxygen Documentation Generator
 - GNU Linker Map files
 - Makefile Tools
 - WSL

cheers!

</details>


# 答案1
**得分**: 4

你应该更改C/C++扩展配置。在`Intellisense Mode`下选择一个合适的配置。在Windows上,默认设置为`windows-msvc-x64`,而在Linux上为`linux-gcc-x64`。创建一个新的C/C++配置(使用`C/C++: Edit Configurations`命令),并将Intellisense Mode设置为`linux-gcc-arm`。然后针对你的项目,使用`"C/C++: Select a configuration..."`命令更改你的配置。

<details>
<summary>英文:</summary>

You should change the C/C++ Extension Configurations. Select a suitable one under the `Intellisense Mode`. On Windows, it is by default set to windows-msvc-x64, and on Linux, linux-gcc-x64. Create a new C/C++ configuration (`C/C++: Edit Configurations` command), and set the Intellisense Mode to `linux-gcc-arm`. Then for your project, using the `&quot;C/C++: Select a configuration...&quot;` command change your configuration.

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/8JVwL.png

</details>



huangapple
  • 本文由 发表于 2023年6月22日 17:05:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530244.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定