the "const" qualifier

rpjday at ccu.umanitoba.ca rpjday at ccu.umanitoba.ca
Wed Aug 1 10:52:00 AEST 1990


  I am trying to decode the ANSI draft in front of me, and am having
trouble interpreting the section on the const qualifier.  Rather than
type out the entire example, I'll just refer to the page and line numbers
in the Feb 14, 1990 draft.
  Section 3.5.3, line 26, we have, "For two qualified types to be
compatible, both shall have the identically qualified version of a 
compatible type..."  Does "compatible" mean assignment compatible?
That is, I am not allowed to do 

	const int i = 10;
	int j;
	j = i;   ???

even though this has no effectg on the value of j?

  This is just the beginning.  At the top of the next page, in the
segment of code, line 7 shows an assignment of a const-qualified
structure to a non-const-qualified structure.  But based on the
previous definition, should this work?  The comment suggests it should.
Clarification, please?

  Finally, line 12 of 3.5.3, "If an attempt is made to modify an object
defined with a const-qualified type through use of an lvalue with
non-const-qualified type, the behavior is undefined."  How would one
do this anyway?  Maybe as follows?

	const int j = 10 ;
	int i ;
	*(&i + 1) = 20 ;

  If i and j are allocated in the standard order on the stack,
this assignment would affect the value of j.  Is this what this statement
refers to ?  Is there another example?
  Thanks for the help.

R. Day
U of Manitoba



More information about the Comp.std.c mailing list