Integral promotion. 
Author Message
 Integral promotion.




:>I admit that I am confused too. So in this case the compiler should issue a
:>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both
:>"x" and "1" are promoted to integers, and there could therefore be a
:>potential loss of precision because "sizeof(int) > sizeof(short)", but no
:>precision could have been lost if int and short had been the same (small)
:>size ?? <phew>
:
:x++ is not the same as "x = x + 1".  "++x" nearly is.

However, they *are* all the same in this context (where the value of
the expression is not used, and overflow is impossible).

I think you were confused by the line:
:>warning for { short x = 0; x++; } since "x++" equals "x = x + 1" and both

Note that this was an English "for", not a C "for" since otherwise
there would be () rather than {} around the snippet, which is
the equivalent of {short x=1;}.

I don't think compilers need to issue warnings for potential loss
of precision in any case, though, but I've been wrong before.
And we all know by now that they *may* issue such warnings at any
time without violating the Standard (even for "x *= 2;").

Cheers,
Stan.
--



Wed, 12 Aug 1998 03:00:00 GMT  
 Integral promotion.



[stuff cut]

)>#  When a value with integral type is demoted to a signed integer with
)>#  smaller size ... if the value cannot be represented the result is
)>#  implementation-defined.
)>
)>Hence implementation-defined behavior occurs.
)
)Thus, the implementation has to say exactly how it handles this.
)There is still some question as to whether the implementation can
)define it as an overflow resulting in program termination, is there
)not?

Where in the standard does it say that a compiler must be accompanied by
-any- documentation?

Mike
----
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

I don't speak for DSC.         <- They make me say that.



Wed, 12 Aug 1998 03:00:00 GMT  
 Integral promotion.

:Re: short = short + short causing a warning.
:
:This is all getting off the track.  Since only a warning is generated this
:has very little to do with the standard.  I think the point is why does
:
:short = short + short;
:
:generate a warning whereas
:
:int = int + int;
:
:does not.  Both these statements are as prone to overflow as each other
:(although in the first case it may not happen until the int resulting
:from the addition is moved into the short if sizeof(int) > sizeof(short).
:
:The warning is even sillier since on the implementation mentioned
:ints and shorts are the same.

I do not own, nor have I read, a copy of the ANSI standard.  That said,
ints in my experience have 'special status' in that it is usually the
machine word size, sort of like an atomic data unit, whereas shorts
are an artificial construction.  Even though the two have the same size
in the example, this may nevertheless influence the behavior of the
compiler.

R.Weathersby



Wed, 12 Aug 1998 03:00:00 GMT  
 Integral promotion.


[snip]

Quote:
> Where in the standard does it say that a compiler must be accompanied by
> -any- documentation?

The standard does not specify "compiler" but does define
"implementation" as:

Quote:
> 3.9 implementation: A particular set of software, running in a
> particular translation environment under particular control options,
> that performs translation of programs for, and supports execution of
> functions in, a particular execution environment.

and immediately specifies that

Quote:
> 3.10 implementation-defined behavior: Behavior, for a correct program
> construct and correct data, that depends on the characteristics of the
> implementation and that each implementation shall document.
> 3.12 locale-specific behavior: Behavior that depends on local
> conventions of nationality, culture, and language that each
> implementation shall document.

The point is made again in:

Quote:
> 4.  Compliance

[snip]

Quote:
> An implementation shall be accompanied by a document that defines all
> implementation-defined characteristics and all extensions.

Note that it does not say that that document shall contain nothing else.
The information may be hard to find.  However, IMHO, it does allow any
customer to ask a supplier to point to that document and to factor the
answer into the buying decision.

Quote:
> 5.2.4.2 Numerical limits
> A conforming implementation shall document all the limits specified in
> this subclause, which shall be specified in the headers <limits.h> and
> <float.h>.
> G.3 Implementation-defined behavior
> Each implementation shall document its behavior in each of the areas
> listed in this subclause.  The following are implementation-defined:

[snip]

This is followed by about 300 lines of detail.  From which, I think you
will gather that the standard writers had a proper regard to
documentation.  However, I think some suppliers must put a meaning
different to mine on the quotation from Clause 4.
--
walter briscoe



Thu, 13 Aug 1998 03:00:00 GMT  
 Integral promotion.

 > Where in the standard does it say that a compiler must be accompanied
 > by -any- documentation?

The last sentence of Clause 4 of ISO/IEC 9899 (the Standard):

 "An implementation shall be accompanied by a document that defines
all implementation characteristics and all extensions."



Thu, 13 Aug 1998 03:00:00 GMT  
 Integral promotion.

Quote:

>)Thus, the implementation has to say exactly how it handles this.
>)There is still some question as to whether the implementation can
>)define it as an overflow resulting in program termination, is there
>)not?

>Where in the standard does it say that a compiler must be accompanied by
>-any- documentation?
>From ANSI Classic 1.6:

" Implementation -- a particular set of software, running in a
particular translation environment under particular control options,
that performs translation of programs for, and supports execution in a
particular exectution environment.

Implementation-defined behavior -- behavior, for a correct program
construct and correct data, that depends on the characteristics of the
implementation and that each implementation shall document."

If a particular implementation doesn't specify each of the explicit
implementation-defined behaviors, it isn't conforming.  

Thad



Thu, 13 Aug 1998 03:00:00 GMT  
 Integral promotion.


On a discussion on   (short) x++ ; /* Warning: Loss of precision */

Quote:
> I don't think compilers need to issue warnings for potential loss
> of precision in any case, though, but I've been wrong before.
> And we all know by now that they *may* issue such warnings at any
> time without violating the Standard (even for "x *= 2;").

Since this is really happening, I would like to know:

1) Is it normal? (as opposed to legal) or should I consider it a bug (a
   legal bug but still a nuisance).

2) _Should_ there be a way to cast ones way out? (Obviously not on this  
   platform)

// Jens M Andreasen



Thu, 13 Aug 1998 03:00:00 GMT  
 Integral promotion.

Quote:

> Where in the standard does it say that a compiler must be accompanied by
> -any- documentation?

Section 3.10/1.6:
# Implementation-defined behavior -- behavior, for a correct program
# construct and correct data, that depends on the implementation
# and that each implementation shall document.

Section 3.12/1.6:
# Locale-specific behavior -- behavior that depends on local conventions
# of nationality, culture, and language that each implementation shall
# document.

Section 4/1.7:
# An implementation shall be accompanied by a document that defines all
# implementation-defined characteristics and all extensions.
--

SoftQuad Inc., Toronto                      -- C. M. Sperberg-McQueen



Thu, 13 Aug 1998 03:00:00 GMT  
 Integral promotion.

Quote:


>>Section 4/1.7:
>># An implementation shall be accompanied by a document that defines all
>># implementation-defined characteristics and all extensions.
>I wonder... does the standard define "a document?"

That would be circular: the "standard" _is_ a document.

Quote:
>To me this implies that a compiler which provided all such information,
>but only in "on-line help" or something, might not be conforming.
>Thoughts?

On-line help falls under the category of "electronic documents", as
far as I'm concerned...  In view of some documentation (on-line or
printed) I have seen, I would be more concerned with exactly _how_ the
"document" defines all implementation-defined issues (i.e. is one
supposed to understand what they're saying?).

==
Miguel Carrasquer Vidal                     ~ ~
Amsterdam                   _____________  ~ ~

========================== Ce .sig n'est pas une .cig



Sat, 22 Aug 1998 03:00:00 GMT  
 Integral promotion.

: >
: >Section 4/1.7:
: ># An implementation shall be accompanied by a document that defines all
: ># implementation-defined characteristics and all extensions.

: I wonder... does the standard define "a document?"

: To me this implies that a compiler which provided all such information,
: but only in "on-line help" or something, might not be conforming.

In the US, in order to have a C compiler validated by NIST (National
Institute of Standards and Technology), you have to provide an actual
document with all the implementation-defined details.  I doubt that
"on-line help" would be acceptable to the validation team.

Walter Murray
Hewlett-Packard
Support Technology Lab



Sun, 23 Aug 1998 03:00:00 GMT  
 Integral promotion.

Quote:



> >>Section 4/1.7:
> >># An implementation shall be accompanied by a document that defines all
> >># implementation-defined characteristics and all extensions.

> >I wonder... does the standard define "a document?"

> That would be circular: the "standard" _is_ a document.

Nah. The fact that the Standard happens to be a document is totally
incidental and has no bearing on the Standard's use of the term
"document" in the context of "the implementation be accompanied by a
document...". The Standard is also a sequence of characters, but that
doesn't mean that providing its own definition of "character sequence"
for the purposes of discussing string literals, or header files, or
whatever, would be circular.

--

Chris Volpe                             Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D                    Fax:   (518) 387-6560



Mon, 24 Aug 1998 03:00:00 GMT  
 
 [ 41 post ]  Go to page: [1] [2] [3]

 Relevant Pages 
 

 
Powered by phpBB® Forum Software