Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: "Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 08:52:52 -0400
John Carson wrote:
[..] By
5.19/3
"An arithmetic constant expression shall satisfy the requirements for
an integral constant expression, except that
- floating literals need not be cast to integral or enumeration type,
- conversions to floating point types are permitted."
Thus 1.0f/0.0f is an "arithmetic constant expression". Is this the
same as a "constant expression" that would make the program
ill-formed. Section 5.19/2 appears to give the answer:
"Other expressions [including arithmetic constant expressions] are
considered constant-expressions only for the purpose of non-local
static object initialization (3.6.2)."
In
int main()
{
float f (1.0f/0.0f);
}
f is not a non-local static object, so 1.0f/0.0f is not a "constant
expression" and therefore the program is *not* ill-formed.
By this reasoning, however,
float f (1.0f/0.0f);
int main()
{
}
is ill-formed. Comeau, however, compiles this program too, so I am
still puzzled.
Compilers have bugs. Undefined behaviour is just that, undefined.
Combine the two and you can have any behaviour either due to compiler
vendor's intent or dispite it, and there is nothing that one could
deduce about code correctness by looking how compilers behave. The
only true sources of information are the Standard and time.
If we think that either VC++ or Comeau C++ misbehave, we need to talk
to the folks who make them. But even then, considering the situation
at hand, you are most likely simply get the response "the behaviour
[of the division by zero] is undefined by the Standard, so we decided
to define it as this..." followed by what you already know, Comeau
lets it slide, VC++ complains.
VC++ is known to be overprotective. I don't know about Comeau in that
regard. It is very likely that if you do get a response from VC++
team, it's going to be one of those "since the 1.f/0.f expression has
undefined behaviour in run-time, we diagnose it for you and protect
you from doing the wrong thing". Then you ask "what about a/b when
b is initialised to 0.f", and you'll hear "well, we're not gods, you
know".
As to the fact that Comeau compiles what seems to be an ill-formed
program, the answer is simple: compilers are allowed to do that. It
might be required to give a diagnostic, but I'm too lazy to find that
out.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
- Follow-Ups:
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: John Carson
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- References:
- C2124 is most disrespectful of IEEE floating point arithmetic
- From: Dr Pizza
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: Doug Harrison [MVP]
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: Dr Pizza
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: Alexander Grigoriev
- Re: C2124 is most disrespectful of IEEE floating point arithmetic
- From: John Carson
- C2124 is most disrespectful of IEEE floating point arithmetic
- Prev by Date: Exporting functions from COM dll in VC++ 6.0 to a VB 6.0 Client App
- Next by Date: Calling virtual method of base class nested in template class (VC++ 6.0)
- Previous by thread: Re: C2124 is most disrespectful of IEEE floating point arithmetic
- Next by thread: Re: C2124 is most disrespectful of IEEE floating point arithmetic
- Index(es):
Relevant Pages
|