Skip to content(if available)orjump to list(if available)

The Linux Kernel Looks to "Bite the Bullet" in Enabling Microsoft C Extensions

fuhsnn

> though some may feel the wrong way around Microsoft C behavior being permitted

The same extension can be enabled with `-fplan9-extensions`, might be more appealing to some!

unwind

Huh. I thought the article was vague on what exactly these extensions permit, so I'd thought I'd look up the GNU documentation. Surprisingly, it [1] was rather vague too!

The only concrete example is:

Accept some non-standard constructs used in Microsoft header files.

In C++ code, this allows member names in structures to be similar to previous types declarations.

    typedef int UOW;
    struct ABC {
      UOW UOW;
    };

[1]: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html#in...

messe

The important one is "Unnamed Structure and Union Fields"[1], in particular unnamed structs and union fields without a tag.

ISO C11 and onward allows for this:

    struct {
      int a;
      union {
        int b;
        float c;
      };
      int d;
    } foo;
In the above, you can access b as foo.b. In ISO C11, the inner struct/union must be defined without a tag. Meaning that this is invalid:

    struct {
      int a;
      union bar {
        int b;
        float c;
      };
      int d;
    } foo;
As is this: union bar { int b; float c; };

    struct {
      int a;
      union bar;
      int d;
    } foo;
-fms-extensions makes both of the above valid. You might be wondering why this is uesful. The most common use is for nicer struct embedding/pseudo-inheritance:

    struct parent {
      int i;
      void *p;
    };

    void parent_do_something(struct parent *p);

    struct child {
      struct parent;
      const char *s;
    };

    struct child *c;
    struct parent *p = (struct child *)c; // valid
    parent_do_something(p);
    c.i++; // valid
[1]: https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html

creshal

Why is this still not standardized?

arguflow

A really good example of it is in this lore thread here [1]. He explains it better than me so I'll just link it here

[1]: https://lore.kernel.org/lkml/200706301813.58435.agruen@suse....

mrlonglong

Microsoft "embrace, extend and takeover" comes to mind here. Caveat emptor.