This is the talk page for discussing improvements to the Enumerated type article. This is not a forum for general discussion of the article's subject. |
Article policies
|
Find sources: Google (books · news · scholar · free images · WP refs) · FENS · JSTOR · TWL |
This article is rated C-class on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Specific confusing sentences:
Foxjwill 18:14, 18 December 2006 (UTC)
I attempted to improve the context. Can we remove the note now? Dw31415 17:17, 10 October 2007 (UTC)
I removed the following from the introduction as most of it is not universally true for all programming languages that support enumerated types and the issues are covered with reference to specific programming languages in the rest of the article.
More about enums:
The enum keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list. Every enumeration type has an underlying type, which can be any integral type except char. The default underlying type of the enumeration elements is int. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example:
enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
In this enumeration, the sequence of elements is forced to start from 1 instead of 0.
A variable of type Days can be assigned any value in the range of the underlying type; the values are not limited to the named constants.
The default value of an enum E is the value produced by the expression (E)0.
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
In this enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. Enumerators can have initializers to override the default values. For example: —Preceding unsigned comment added by 81.155.142.9 (talk) 19:23, 3 August 2008 (UTC)
This puts the first usage of enums in C in the ANSI standard. I recall reading about enums (together with changing structs in C to be like PL/1 / Pascal structs) in BYTE in 1983. I believe this change was for PWB UNIX 7 (6?).Mzk1 (talk) 16:29, 29 December 2011 (UTC)
Currently the article begins this way:
This strikes me as poorly expressed, if not wrong. I think that something like this might capture the idea better:
I think this concept could be expressed in a Python-like pseudocode this way:
class Color: pass # define the class Color
blue = Color() # enumerate the valid instances of color
red = Color()
yellow = Color()
colors = [red, yellow, blue] #define an ordered list of all valid colors
Comments? StephenFerg (talk) 00:36, 14 August 2012 (UTC)
So how can enums exist in languages without classes? 1Z (talk) 12:02, 14 August 2012 (UTC)
@Lipsio: I agree. In particular, enumerated types are not limited to "computer programming". For example, they are widely used in hardware descriptions:
type state_type is (S0, S1, S2, S3); -- enumerated type in VHDL
Lambtron talk 14:58, 18 November 2020 (UTC)
Ushkin N (talk · contribs) recently split off parts of the article Enumerated type to a page Comparison of programming languages (types, enums) (diff). This page then was speedily deleted under A10: Recently created article that duplicates an existing topic. While I don't think that reason applies as Comparison of programming languages (types, enums) clearly was intended to be a split page, I still am not sure that splitting off that content is an improvement. – Tea2min (talk) 08:09, 22 May 2016 (UTC)
Would this be a good addition? On top of my head I know MySQL and PostgreSQL support enums. Nsz no (talk) 10:43, 4 January 2017 (UTC)
Hello fellow Wikipedians,
I have just modified one external link on Enumerated type. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:
When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.
This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template ((source check))
(last update: 18 January 2022).
Cheers.—InternetArchiveBot (Report bug) 17:50, 21 September 2017 (UTC)
enum cardsuit {
Clubs = 1,
Diamonds = 2,
Hearts = 4,
Spades = 8
};
...
// a possible use
enum cardsuit card;
...
if ( card & (Diamonds | Hearts) ) ... // action for red suits
else if ( card & (Spades | Clubs ) ... // action for red suits
else ... // action for out of range error
Tbere are better ways to exemplify this, however this, but I don't want to write another example because it has to be consistent with the rest of the article — Preceding unsigned comment added by 2806:106E:B:400F:F9:F69F:2ED7:3753 (talk) 06:32, 4 September 2022 (UTC)
The beginning of the article lists R factors as an example of enumerated types. However, while R factors are indeed lists of named values, they are used to efficiently store categorical data and are not usually used in the same ways other languages use enums. They would in fact be quite cumbersome for those kinds of usage. I believe that this reference to R factors should be removed. Semcebag (talk) 10:37, 13 January 2024 (UTC)