3

I'm doing some work on a C++ named parameters feature, specifically labelled argument syntax design, and I've found that there is an old deprecated form of designated initialization that uses the identifier : expression syntax rather than . identifier = expression syntax.

See https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html:

Another syntax that has the same meaning, obsolete since GCC 2.5, is ‘fieldname:’, as shown here:

struct point p = { y: yvalue, x: xvalue };

I see this is still supported, but warns deprecated, in GCC and Clang codebase. (Not sure on MSVC or EDG.)

My question is: why was this deprecated and/or obsoleted ? Anyone know the history there, or how I could find out more? Or who would know more?

Andrew Tomazos
  • 66,139
  • 40
  • 186
  • 319
  • Maybe just because too many ways to do the same thing causes confusion? – Fantastic Mr Fox Aug 12 '21 at 00:53
  • 5
    Do you really want to know why it was deprecated or why the C standards committee didn't adopt it and instead chose a different syntax in C99? I would assume it was deprecated in favor of the standard syntax. – jamesdlin Aug 12 '21 at 00:55
  • 2
    Caution, danger ahead: https://stackoverflow.com/questions/53250463/why-c20-doesnt-support-out-of-order-designated-initializer – Craig Estey Aug 12 '21 at 01:10
  • @jamesdlin: I guess there is WG14 N494 from 1995 http://www.open-std.org/jtc1/sc22/wg14/www/docs/n494.pdf but I don't see any discussion of syntax design. There is earlier N473 25 Aug 95 Keaton, Rationale for Designated Initializers, but document link is broken in http://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log.htm , I wonder if N473 mentions it. – Andrew Tomazos Aug 12 '21 at 01:24
  • @AndrewTomazos Perhaps, not strictly relevant since you're worried about deprecated [for 20 years?] syntax for designated initializers ... My _guess_ as to why: Aside from the standardization, `.x = 23` is more like `[3] = 37` syntactically than `x: 23`. They're more similar to what you can say (in code): `instance.x = 23;` but not `instance:x = 23;` As to the link, if you're only going to use them in C, then no worries ... But, if you're planning to use them in C++, just be aware that they're severely restricted. – Craig Estey Aug 12 '21 at 01:47
  • gcc has historically been used on occasion to experiment with potential language or library features - for example to test feasibility of implementation before a new feature is considered for incorporation into the C++ standard. Not all of those experimental features make it into a standard, but are in releases of gcc. This then means a set of non-standard features in gcc. If those features are also not used much by developers, they may be deprecated (tagged for removal from some future release of gcc) - and eventually removed. – Peter Aug 12 '21 at 01:51

1 Answers1

3

GCC of that vintage included release notes in a file called NEWS in the source tree. The GCC 2.5.8 distribution has the release notes of 2.5, which says:

  • The C syntax for specifying which structure field comes next in an initializer is now .FIELDNAME=. The corresponding syntax for array initializers is now [INDEX]=. For example,
  char whitespace[256]
    = { [' '] = 1, ['\t'] = 1, ['\n'] = 1 };

This was changed to accord with the syntax proposed by the Numerical C Extensions Group (NCEG).

The GCC developers had previously seen the need for an extension to C89 allowing for what we now call designated initializers (they called them "labeled elements"). So they had made up their own, following the syntax FIELDNAME: val for structs and unions, and [INDEX] val for arrays. Apparently the NCEG folks liked this but thought the other syntax would be better, though I'm not sure what significant difference they saw between them. So GCC switched to NCEG's preferred syntax, which is what eventually was adopted into C99.

The old syntax was then considered deprecated, but apparently support was never dropped, and when clang came along, it evidently picked it up in the interest of full GCC compatibility.

The early GCC designers were quite fond of adding extensions to the language whenever they thought they would be useful. Several of them eventually made it into C99 in one form or another, for instance long long int, variable-length arrays, variadic macros, inline, and __FUNCTION__.

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
  • This seems to be circa 1992-1994, so it predates standardization of designated intialization in 1995 in C. The WG14 document mentions that Ken Thompson implemented it in a compiler at AT&T. I wonder if that "compiler at AT&T" and gcc were one and the same? – Andrew Tomazos Aug 12 '21 at 02:30
  • Also, it looks like NCEG was formed 1992: http://computer-programming-forum.com/47-c-language/02a1a9bbf583e17f.htm – Andrew Tomazos Aug 12 '21 at 02:33
  • @AndrewTomazos: More likely [PCC](https://en.wikipedia.org/wiki/Portable_C_Compiler). The whole point of GCC, and indeed the rest of the GNU project, was to replace the software coming out of places like AT&T, whose licenses they considered too restrictive. – Nate Eldredge Aug 12 '21 at 18:33