It seems to me that a lot, if not most, compilers treat enumerated types as int underneath. In C/gcc, enums are compiled to int. In C#/Visual C#, you can change the underlying data type with something like:
enum Days : byte {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; but the default is int (second paragraph) if you don't change the type.
For obvious reasons, ints are efficient. They fly through the ALU with ease and avoid useless string comparisons.
Upon first glance, it doesn't seem that interpreted languages have enumerated types built-in (Ruby, Perl, JavaScript, others I'm sure). They can be emulated though; i.e. in JavaScript.
My questions:
- Why do (seemingly) most compilers use
intas the underlying type? Is the reason historical/performance-related? - Are there languages that compile enumerated types to something other than
int(orbyte,long, numerical types...)? If so, why did they choose to do it differently?