Talk:Enumerated type

Context template
Specific confusing sentences:
 * "Typically the compiler will select a small integer to represent each enumeration value at run-time, but this representation is not always visible to the programmer." Why does the compiler do this? Why isn't it visible to the programmer?
 * Answer: For example, the purpose of the three symbols (apple,orange,banana) is to identify a fruit, not a number! How the values (fruits) are represented is not important to anyone but the compiler and the CPU, hence it is hidden from the programmer. This can be compared to the binary representation of characters or real numbers (or jpg-pictures or MP3-songs for that matter), normally not so interesting to the programmer or user either. / HenkeB 17:02, 2 March 2007 (UTC)


 * I disagree with HenkeB regarding the importance of knowing the values. Some debuggers will show the integer value of fruit as 3 and the programmer has no way of knowing that the fruit is yellow and has a peal (i.e. it is equal to a banana )!  DGerman (talk) 22:56, 27 November 2021 (UTC)


 * "In some languages, the boolean type of truth values is considered a predeclared enumerated type of two values." What is a predeclared enumerated type?
 * Answer: As if somebody had written type boolean = (false,true) at the beginning of every source file.

Foxjwill 18:14, 18 December 2006 (UTC)

Improved Context
I attempted to improve the context. Can we remove the note now? Dw31415 17:17, 10 October 2007 (UTC)

Removed from Introduction
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)

Enum (C) history
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)

Problem with definition of enum
Currently the article begins this way:


 * In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type.

This strikes me as poorly expressed, if not wrong. I think that something like this might capture the idea better:


 * In computer programming, an enumerated type (also called enumeration or enum) is combination of (a) a class and (b) an ordered list or unordered set of named instances of that class, where the list or set contains, and so specifies, all valid instances of the class. The instances are called elements, members or enumerators of the type.

I think this concept could be expressed in a Python-like pseudocode this way:

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)
 * See Planning poker - the physical meaning. Seagateups (talk • contribs) 22:38, 19 November 2015 (UTC)


 * An enumerated type is a set of integers to which names are assigned. Keeping things as simple as possible, but no simpler, that is the definition that belongs in the lede. Vincent J. Lipsio (talk) 13:14, 20 November 2015 (UTC)

I agree. In particular, enumerated types are not limited to "computer programming". For example, they are widely used in hardware descriptions: Lambtron  talk  14:58, 18 November 2020 (UTC)


 * Yes, they are used in hardware, and I've often mapped HW enumerations into C Language structures. I've long intended to add a real-life example of that to this article, and perhaps now will. Vincent J. Lipsio (talk) 19:32, 19 November 2020 (UTC)


 * Great! That would be a very useful addition. In conjunction with that, it seems reasonable to revise the lede along the lines you suggested above. Also, I think (1) the distinction between enum type declarations and instances should be more prominent and clear, (2) "classes" should not be so prominent because they are language-specific type declarations, and (3) it should be stated that an instance may be a variable or a constant. Lambtron  talk  20:41, 19 November 2020 (UTC)

Split off to page Comparison of programming languages
recently split off parts of the article Enumerated type to a page Comparison of programming languages (types, enums). 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)

Add list of databases that support enum under "Databases" section
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)

External links modified
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:
 * Added archive https://archive.is/20130201203915/http://www.rps-obix.com/docs/manuals/enumerated_data_type.html to http://www.rps-obix.com/docs/manuals/enumerated_data_type.html

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

Cheers.— InternetArchiveBot  (Report bug) 17:50, 21 September 2017 (UTC)

add an example on how to use enums like Pascal's sets
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)

Enums in R
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)