Can enumerations hold Char?

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I figured they could, since char is an integral value and it would be able to cast it right? But is it worth it, good style, etc?

Share on other sites
It is possible, it might even be useful in some cases. I'd say in general, it's poor design, but there could exist places where it's the simplest thing that might work.

Share on other sites
They can. If it solves your problem in a simple way, and is clear to someone reading the code, then I'd say it's good design. I'm intrigued to know what you're thinking of using it for.

Share on other sites
Quote:
 Original post by Si0nI figured they could, since char is an integral value and it would be able to cast it right? But is it worth it, good style, etc?

You didn't mention which language you're using, but if the language you're talking about supports changing the underlying type of an enumeration, make sure it allows a change to char before you start planning. For instance, while C# allows you to change the underlying type of an enumeration, it doesn't let you switch to char (for various reasons).

In general, though, you should feel free to do whatever you like with enumerations as long as it's good programming practice. Writing out an enumeration like

enum Numbers{  Zero = '0',  One  = '1',  // ...}

is a bit silly, for instance.

[Edited by - kSquared on January 8, 2005 10:57:50 AM]

Share on other sites
Quote:
 Original post by HarryWThey can. If it solves your problem in a simple way, and is clear to someone reading the code, then I'd say it's good design. I'm intrigued to know what you're thinking of using it for.

Nothing really, jsut out of cursiosity. ;)

And I'm using C/C++