英文:
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 "expected a ';'C/C++(65)".
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 `"C/C++: Select a configuration..."` command change your configuration.
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/8JVwL.png
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论