struct a {
struct *a next;
};
struct b {
struct *b next;
};
was illegal because the second declaration of "next" is a redeclaration. struct a {
struct *a next;
};
struct b {
struct *b next;
};
was illegal because the second declaration of "next" is a redeclaration. #define st_mtime st_mtimensec.tv_sec
POSIX preserves many prefixes for this reason. C99 brought anonymous unions (a Plan 9 invention), which makes many of these API tricks possible without using macros.I've known for a long time that Microsoft headers make use of anonymous unions, which makes it a rare case where they have implemented a recent ISO C feature ahead of time. I seem to recall GCC in the same timeframe would accept this with a warning that it's nonstandard. [I guess not anymore.]
struct foo { union { int i; double d; }; }
Visual Studio also supports anonymous tagged members, union bar { int i; double d; };
struct foo { union bar; };
Is the latter more common in Microsoft land? I've always thought the latter were more useful and wished they were standardized. Anonymous tagged fields make it possible to reuse plain struct and union definitions, permitting a simple form of inheritance; whereas with untagged fields you have to rely on macros for sharing definitions.GCC (https://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html) and clang (confirmed macOS clang-1001.0.46.4) support anonymous tagged members with -fms-extensions, but I can't bring myself to make use of it as I still try to keep many of my projects working with Sun Studio and otherwise try to avoid non-standard features.
I don't know if I have an authoritative sample on that. I saw it exactly once when I worked at MS and I thought it was weird. But I guess it aids in the "psuedo-inheritance" game that people play with structs and their first member being a "base class". Like GObject or gtk+ do. Or struct sockaddr, which duplicates the first few fields.
struct a *next;
or was putting the asterisk before the type name legal back then?I find code dealing with structures that have their members prefixed with a unique prefix much easier to read, usually.
Given the pervasiveness of APIs that contain struct definitions nowadays, it's also understandable that the unique-constraint was removed.
I have not seen a case of it creating problems where there weren't already plenty of other problems with the code and metaprograming had to be abandoned anyway. But it does create problems.
Then again, OCaml still has module-scoped scoped record field names today, even though it also uses the dot syntax.