2

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!

10
  • 2
    @abelenky OP is not using Visual C++.
    – Ian Abbott
    Jun 22 at 9:09
  • 2
    Given the structure definition, __attribute__((__packed__)) seems useless.
    – chqrlie
    Jun 22 at 9:23
  • 1
    @Serkan it is mentioned "And yet this code compiles and runs just fine even with -Wall and -Wextra compiler flags set." Therefore that message seems to come from Intellisense, not from the compiler.
    – Gerhardh
    Jun 22 at 9:33
  • 1
    @GregoryFenn: my comment was meant as a joke :) The problem seems to be a configuration issue: VS Code uses a language server that does not support the gcc extension __attribute__. You might want to add #ifdef _MSC_VER #define __attribute__(x) #endif
    – chqrlie
    Jun 22 at 9:37

1 Answer 1

4

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
  • Thank you! (New to VS Code, the User/Workspace settings for my multiple folders got me a bit confused :) ) Jun 22 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.