Two patches queued into the Linux kernel’s build system development tree, kbuild-next, would enable the -fms-extensions compiler argument everywhere for allowing GCC and LLVM/Clang to use the Microsoft C Extensions when compiling the Linux kernel. Being in kbuild-next these patches will likely be submitted for the Linux 6.19 kernel merge window next month but remains to be seen if there will be any last minute objections to this change.

The -fms-extensions compiler option honored by the GNU Compiler Collection and LLVM/Clang allow enabling some non-standard C/C++ constructs used within Microsoft header files and honored by the the Microsoft Visual C/C++ compiler. For Linux kernel development purposes, enabling the Microsoft C Extensions would allow including a tagged struct or union anonymously in another struct/union.

  • DeltaWingDragon@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    20 hours ago

    What’s the point of this? If you have a struct within a struct, you probably want them to nest. The -fms-extensions will un-nest them, which is not what you mean.

    // If I type this:
    struct test {
            int a;
            struct test2 {
                    char b;
                    float c;
            };
            double d;
    };
    
    struct test my_test;
    
    // I want this to happen:
    my_test.test2.b = 'x'; //assigning the members of the nested struct
    my_test.test2.c = 3.141; //this will work
    printf("%f", my_test.c); //this will NOT work since c is a property of test2
    
    • entwine@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      19 hours ago

      You can already do that in standard C like this:

      struct test {
              int a;
              struct {
                      char b;
                      float c;
              } test2;
              double d;
      };
      

      I can’t think of any particular reason why you’d want an unnamed struct inside a struct, but you definitely would want to be able to have an unnamed struct inside a union. I suspect the struct-inside-struct thing can become useful in some scenarios involving unions.