Error in Annex J

Error in Annex J

Post by Keith Thom » Wed, 31 Oct 2007 17:53:46


J.2 lists the following as an instance of undefined behavior:

Conversion to or from an integer type produces a value outside the
range that can be represented (6.3.1.4).

This is incomplete and misleading. 6.3.1.4 discusses conversions
between floating-point and integer types; for such conversions, the
statement in J.2 is correct. But for a conversion from an integer
type to a signed integer type, an overflow either yields an
implementation-defined result or raises an implementation-defined
signal (6.3.1.3p3).

I think the quoted statement in J.2 just needs to mention
floating-point.

Credit goes to Richard Bos for noticing this, in the comp.lang.c
thread "Understanding a simple C program".

--
Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.yqcomputer.com/ ~kst>
San Diego Supercomputer Center <*> < http://www.yqcomputer.com/ ~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
 
 

Error in Annex J

Post by lawrence.j » Thu, 01 Nov 2007 00:46:51


Noted. Anyone have a problem with:

-- Conversion between a real floating type and an integer type
produces a value outside the range that can be represented
(6.3.1.4).

-Larry Jones

When you're as far ahead of the class as I am, it doesn't take much time.
-- Calvin

 
 
 

Error in Annex J

Post by rlb » Thu, 01 Nov 2007 01:56:13


I, at least, have no problems with that. Though since I'm the one who
first was careless enough to misinterpret the original, that may not
mean much...

Richard
 
 
 

Error in Annex J

Post by Wojtek Ler » Thu, 01 Nov 2007 02:03:28


I don't think this makes a lot of sense. It's impossible for a conversion
to some type to produce a value outside of that type. That is why the
behaviour needs to be undefined instead.

(BTW There are a few places in the standard that use similar wording.)
 
 
 

Error in Annex J

Post by Douglas A. » Thu, 01 Nov 2007 08:18:37


It is in the list of undefined behavior. Maybe your point is
that it should say
-- Conversion between a real floating type and an integer type
would produce a value outside the range that can be represented
(6.3.1.4)
 
 
 

Error in Annex J

Post by Keith Thom » Thu, 01 Nov 2007 09:02:45

"Douglas A. Gwyn" < XXXX@XXXXX.COM > writes:





That sounds good. (I could pedanticize at length on the meaning of
"would produce", but just this once I'll refrain and agree that the
wording is clear enough.)

--
Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.yqcomputer.com/ ~kst>
San Diego Supercomputer Center <*> < http://www.yqcomputer.com/ ~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
 
 

Error in Annex J

Post by Wojtek Ler » Thu, 01 Nov 2007 11:49:17


Yes, that definitely sounds much better to me. And yes, my point was that
saying that the behaviour is undefined when the conversion *produces* a
value outside of its type is bad logic -- since the behaviour is undefined,
the conversion may actually produce a value that isn't outside its type, and
that doesn't make the behaviour any less undefined.