From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: enum types and casting
Date: Sun, 29 Apr 2007 11:10:26 +0530 [thread overview]
Message-ID: <46342FCA.1090400@gmail.com> (raw)
Hello. Just now I learnt that enums can be very usefully used as types,
and was experimenting some with it. The following questions arose.
1. Are enums allowed as types only in C++ and not in C? gcc rejects
using an enum as a type whereas g++ accepts it.
2.
Consider:
enum BODY { SUN, MOON, STAR } ;
enum PLANET { EARTH, VENUS, MARS, PLUTO } ;
int main ( void )
{
BODY body ;
// body = 1 ; // gives error
// body = EARTH ; // gives error
body = (BODY) 1 ; // does not give error. expected.
body = (BODY) EARTH ; // does not give error. expected.
body = 3 ; // does not give error. unexpected.
body = (BODY) PLUTO ; // does not give error. unexpected.
}
When the target enum of the cast contains no name that has the same
integer value as the value being casted, how does g++ accept the cast?
Is this expected behaviour or a bug?
Thanks as always.
Shriramana Sharma.
P.S: Oops, silly me, Pluto isn't a planet any more...
next reply other threads:[~2007-04-29 5:40 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-29 5:40 Shriramana Sharma [this message]
2007-05-04 11:26 ` enum types and casting leslie.polzer
2007-05-04 12:18 ` Steve Graegert
2007-05-16 18:37 ` Shriramana Sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46342FCA.1090400@gmail.com \
--to=samjnaa@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).