This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [c++] switch ( enum ) vs. default statment.
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Paweł Sikora <pluto at agmk dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 29 Jan 2007 09:16:12 -0800
- Subject: Re: [c++] switch ( enum ) vs. default statment.
- References: <45BDC001.8000801@agmk.net>
Paweł Sikora wrote:
>> On the other hand, if you are writing a portable library designed
>> to be used with other people's programs, you might every well want
>> the warning -- because you can't be sure that they're not going to
>> pass "7" in as the value of "e", and you may want to be robust in
>> the face of this *unspecified* behavior.
>
> sorry, i don't care about unspecified/undefined behavior triggered
> by users glitches. it's not a problem of my library.
The point I was trying to make was that "unspecified" and "undefined"
are actually very different. I wouldn't be too surprised if, in the
future, G++ defined the behavior of the "e = (E) 7" case as storing the
value in the underlying type. Then, might indeed rely on that.
Obviously, you're free to make your own decisions, but, personally, I
would certainly feel free to assume that no undefined behavior happened
in the application -- but I wouldn't assume that no unspecified behavior
occurred.
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713