From: Jeffrey A Law <law@hurl.cygnus.com>
To: Joe Buck <jbuck@Synopsys.COM>
Cc: gavin@cygnus.com, cgw@alum.mit.edu, egcs@egcs.cygnus.com
Subject: Re: [PATCH] Fix for short-enums comparison bug
Date: Thu, 11 Feb 1999 11:55:00 -0000 [thread overview]
Message-ID: <6271.918762821@hurl.cygnus.com> (raw)
In-Reply-To: Your message of Thu, 11 Feb 1999 11:42:26 MST. < 199902111942.LAA16560@atrus.synopsys.com >
In message < 199902111942.LAA16560@atrus.synopsys.com >you write:
> Wrong. The ISO C++ standard defines what values must be assignable to the
> enum, and it is a larger set of values than just the members. I don't
> have the language in front of me, but the intent is to require the ability
> to hold intermediate values and AND and OR of legal values. Thus code
> like the following is standard-conformant:
>
> enum flags {
> flag_none = 0x0,
> flag_a = 0x1,
> flag_b = 0x2,
> flag_c = 0x4,
> flag_d = 0x8
> };
>
> ...
> flags foo = (flags)(flag_a | flag+b); // OK
> flags bar = (flags) 12; // OK
> flags xyz = (flags) 23; // not OK
>
> the last one is not guaranteed to work because the compiler is allowed to
> use a four-bit unsigned field and 23 will not fit.
OK. Thanks. So if we go back to the original sample code:
typedef enum {A=0, B, C, D} T;
main(){
T x;
for (x=A; x<=D; ++x)
printf("%d ", (int)x);
putchar('\n');
}
So the compiler could use a 2 bit unsigned field for x since the values for
enum T are 0, 1, 2, 3. Other values will not fit and would be considered
invalid. Thus removing the test x <= D is technically valid for C++. Right?
That (of course) isn't binding for C.
jeff
WARNING: multiple messages have this Message-ID
From: Jeffrey A Law <law@hurl.cygnus.com>
To: Joe Buck <jbuck@Synopsys.COM>
Cc: gavin@cygnus.com, cgw@alum.mit.edu, egcs@egcs.cygnus.com
Subject: Re: [PATCH] Fix for short-enums comparison bug
Date: Sun, 28 Feb 1999 22:53:00 -0000 [thread overview]
Message-ID: <6271.918762821@hurl.cygnus.com> (raw)
Message-ID: <19990228225300.RaulNT9Woilxsow9uam8RoZQOxUvtBv2Akp8YlTrpCU@z> (raw)
In-Reply-To: <199902111942.LAA16560@atrus.synopsys.com>
In message < 199902111942.LAA16560@atrus.synopsys.com >you write:
> Wrong. The ISO C++ standard defines what values must be assignable to the
> enum, and it is a larger set of values than just the members. I don't
> have the language in front of me, but the intent is to require the ability
> to hold intermediate values and AND and OR of legal values. Thus code
> like the following is standard-conformant:
>
> enum flags {
> flag_none = 0x0,
> flag_a = 0x1,
> flag_b = 0x2,
> flag_c = 0x4,
> flag_d = 0x8
> };
>
> ...
> flags foo = (flags)(flag_a | flag+b); // OK
> flags bar = (flags) 12; // OK
> flags xyz = (flags) 23; // not OK
>
> the last one is not guaranteed to work because the compiler is allowed to
> use a four-bit unsigned field and 23 will not fit.
OK. Thanks. So if we go back to the original sample code:
typedef enum {A=0, B, C, D} T;
main(){
T x;
for (x=A; x<=D; ++x)
printf("%d ", (int)x);
putchar('\n');
}
So the compiler could use a 2 bit unsigned field for x since the values for
enum T are 0, 1, 2, 3. Other values will not fit and would be considered
invalid. Thus removing the test x <= D is technically valid for C++. Right?
That (of course) isn't binding for C.
jeff
next prev parent reply other threads:[~1999-02-11 11:55 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <x490ee6l2e.fsf@janus.pgt.com>
1999-02-10 23:47 ` Jeffrey A Law
[not found] ` < 4691.918719200@hurl.cygnus.com >
1999-02-11 6:55 ` Gavin Romig-Koch
[not found] ` < 14018.60839.325601.426391@cetus.cygnus.com >
1999-02-11 7:25 ` Joern Rennecke
1999-02-28 22:53 ` Joern Rennecke
1999-02-11 8:12 ` Charles G Waldman
1999-02-28 22:53 ` Charles G Waldman
1999-02-11 9:33 ` Jeffrey A Law
[not found] ` < 5858.918754318@hurl.cygnus.com >
1999-02-11 11:40 ` Gavin Romig-Koch
1999-02-28 22:53 ` Gavin Romig-Koch
1999-02-11 11:44 ` Joe Buck
[not found] ` < 199902111942.LAA16560@atrus.synopsys.com >
1999-02-11 11:55 ` Jeffrey A Law [this message]
[not found] ` < 6271.918762821@hurl.cygnus.com >
1999-02-11 12:07 ` Joe Buck
1999-02-28 22:53 ` Joe Buck
1999-02-11 14:16 ` Tim Hollebeek
[not found] ` < 199902112216.RAA27319@wagner.Princeton.EDU >
1999-02-11 14:19 ` Jeffrey A Law
[not found] ` < 6754.918771465@hurl.cygnus.com >
1999-02-11 17:03 ` Joe Buck
1999-02-28 22:53 ` Joe Buck
1999-02-28 22:53 ` Jeffrey A Law
1999-02-28 22:53 ` Tim Hollebeek
1999-02-28 22:53 ` Jeffrey A Law
1999-02-28 22:53 ` Joe Buck
1999-02-28 22:53 ` Jeffrey A Law
1999-02-28 22:53 ` Gavin Romig-Koch
1999-02-28 22:53 ` Jeffrey A Law
1999-02-11 12:12 Mike Stump
1999-02-28 22:53 ` Mike Stump
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=6271.918762821@hurl.cygnus.com \
--to=law@hurl.cygnus.com \
--cc=cgw@alum.mit.edu \
--cc=egcs@egcs.cygnus.com \
--cc=gavin@cygnus.com \
--cc=jbuck@Synopsys.COM \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).