🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1549

Re: the "const" qualifier

#1549
From: Doug Gwyn
Date: Wed, 01 Aug 1990 13:44
42 lines
1979 bytes
In article <1990Aug1.005200.21645@ccu.umanitoba.ca> rpjday@ccu.umanitoba.ca writes:
-  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?

No, "compatible type" is a technical term defined in section 3.1.2.6.

-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?

I don't understand your example.  Certainly it is allowed, and the
value of j is definitely affected (it is set to 10).

-  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.

Of course it should work.  What argumentation would you offer for it
being disallowed?

You cannot store INTO a const-qualified object; however, you may
pick up its contents!

-  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?

	const int j = 10;
	int *p = (int *)&j;
	*p = 20;

- Maybe as follows?
-	const int j = 10 ;
-	int i ;
-	*(&i + 1) = 20 ;

Yuck!  That's horrible code, which one has no reason to expect to work.
Technical Details
Message-ID: <13462@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ncifcrf!lhc!adm!smoke!gwyn
References: <1990Aug1.005200.21645@ccu.umanitoba.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!ncifcrf!lhc!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: the "const" qualifier
Message-ID: <13462@smoke.BRL.MIL>
Date: 1 Aug 90 13:44:32 GMT
References: <1990Aug1.005200.21645@ccu.umanitoba.ca>
Organization: U.S. Army Ballistic Research Laboratory, APG, MD.
Lines: 42