www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/18/13:15:04

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [OT] About const int
Date: 18 Jul 2001 17:14:50 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 24
Message-ID: <9j4g6a$qel$1@nets3.rz.RWTH-Aachen.DE>
References: <5BF60CD649EDD411A04600B0D049F53AFFA913 AT hydmail02 DOT hyd DOT wilco-int DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 995476490 27093 137.226.32.75 (18 Jul 2001 17:14:50 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 18 Jul 2001 17:14:50 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Prashant Ramachandra <rprash AT wilco-int DOT com> wrote:
> I have a question that's probably got nothing to with DJGPP, so please
> forgive me for this off-topic post.

> I tried the program below and interestingly, it gives me...

> "Constant is 10. It is actually 1"

That program is very incorrect. It causes undefined behaviour at the
point of the cast from (const int *) to (int *). Gcc would have warned
you about this, if only you had asked for assistance (rule of thumb:
always use '-Wall' unless you have very good reasons not to).

> Shouldn't gcc not make the assumption that the value of j *is* 10 and
> instead reference itfrom memory instead.

No, it shouldn't. You'll have to make up your mind: either j *is*
constant, or it isn't. You can't have it both ways.

If you lie to the compiler like in this piece of source code, _you_
take responsibility for all consequences.
-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019