C9X Revision Proposal

Title:  Nonzero Default Initial Values

Document WG14 N427 / X3J11 95-028

Author:  David Keaton
Author Affiliation:  Keaton Consulting
E-mail Address: 
Sponsor:
Date:  1995-05-29

Proposal Category:
_ Editorial change/non-normative contribution
_ Correction
X New feature
_ Addition to obsolescent feature list
_ Addition to Future Directions
_ Other (please specify) _____________________________
Area of Standard Affected:
_ Environment
X Language
_ Preprocessor
_ Library
      _ Macro/typedef/tag name
      _ Function
      _ Header
Prior Art:  C++
Target Audience:
Those who would like part of the C++ constructor functionality but without the run time overhead.  Users wishing to shorten the repetitive portions of Compound Literals.
Related Documents (if any):
C++ Draft Standard.
Classes in C -- Part 1:  Basic Classes, C9X Proposal, Jervis.
(SC22WG14.1168) Thoughts on Mining C++ Features, Jaeschke.
Designated Initializers, C9X Proposal, Prosser & Keaton.
Compound Literals, C9X Proposal, Prosser & Keaton.
Proposal Attached:
_ Yes
X No, but what’s your interest?

Abstract

One of the uses of C++ constructors is to supply default values for some members, and allow other members to be initialized via arguments to the constructor.  The static portion of this functionality can be emulated in C without the run time overhead by providing a mechanism to specify a nonzero default initial value on a per-type basis.  Then at each variable definition, any member values that are desired to be different from the default can be filled in using Designated Initializers.

In addition, nonzero default initial values could be used to shorten the specification of Compound Literals for a given type, with only the nondefault members being filled in via Designated Initializers.

Note that there are other uses for C++ constructors as well;  these are not addressed here.  However, nonzero default initial values may relieve some of the pressure to implement full-blown constructors in C, with their attendant run time overhead.

Proposal

The author will monitor interest in this subject before providing a more detailed proposal.