Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Type system protocols rest atop fundamental data Date: Fri, 16 Jun 2017 09:11:47 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <31b443b2-2142-417f-812a-955280ff39d8@googlegroups.com> <1d495f2d-77f2-4a89-b695-ae74df6ea664@googlegroups.com> <61bd06fe-a176-4dfc-b437-9090f469d006@googlegroups.com> <503ddc74-df9d-45b6-af6f-04d81d294bd3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="512e3ac5c0dae2d372e7b11219066eb5"; logging-data="27895"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+faMc94LHAg15MzXSInhl9" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:bOSljvgL5jWCBY7gP1SQBMNmoNw= sha1:mLwOD0XuUgCigZ4I5GTvS+sI6Ic= Xref: csiph.com comp.lang.c:112349 Richard Heathfield writes: > On 16/06/17 04:12, Ian Collins wrote: > >> >> More strongly typed enums is one case of the C++ committee listening to >> the programmer community. Why C didn't follow suit is a mystery to me. > > Has it not occurred to you that the C committee might have stuck to less > strongly typed enums because they, too, listened to the programmer > community? > > There's a *reason* we have more than one language. Here's what the ANSI C Rationale https://www.lysator.liu.se/c/rat/ says. It doesn't directly address "listening to the programmer community", but the desire to reflect common practice and avoid breaking existing code points in that direction. Enumerations permit the declaration of named constants in a more convenient and structured fashion than #define's. Both enumeration constants and variables behave like integer types for the sake of type checking, however. The Committee considered several alternatives for enumeration types in C: 1. leave them out; 2. include them as definitions of integer constants; 3. include them in the weakly typed form of the UNIX C compiler; 4. include them with strong typing, as, for example, in Pascal. The Committee adopted the second alternative on the grounds that this approach most clearly reflects common practice. Doing away with enumerations altogether would invalidate a fair amount of existing code; stronger typing than integer creates problems, for instance, with arrays indexed by enumerations. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"