🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pilot.programmer.codewarrior
Article #63

Re: strange variable behavior

#63
From: meeroh
Date: Sun, 15 Apr 2001 18:51
50 lines
2260 bytes
In article <8rmjdtcv4ngqtjnbci7gbq1vg7tjmlqh6r@4ax.com>,
 Doug Crocker <dcrocker@newsNOSPAMguy.com> wrote:

>Can anyone explain this one? Is there a patch or something we don't
>have?  I have a function with 3 UInt32 in it when I set one variable
>to a value all 3 get changed to that value here is an example
>
>
>static Boolean VarTest()
>{
>  UInt16    recordNum;
>  Int32     TotRecords;
>  UInt32    error;
>
>  recordNum = 1;    // when recordNum is set to 1 TotRecords and error
>                    //  are also set to 1
>  error = 0;        // now error, recordNum and error are set to 0
>  TotRecords = 99;  // here all 3 are set to 99
>
>  return 1;
>}
>
>Using new copy of CodeWarrior 7 under windows 98.
>
>Any ideas on this and/or how to fix it?

There is nothing to fix. The compiler is using the same register to 
store all 3 variables because the way you use them allows it to do that 
(i.e. the lifetimes of the variables do not overlap).

If you did something like

a = 1;
b = 2;
c = 3;

if (a == 1) {
   a = 1;
} else if (b == 2) {
   b = 2;
} else if (c == 3) {
   c = 3;
}

then their lifetimes would overlap and the compiler would not optimize 
that away.

meeroh
-- 
You can get random signatures if you put text files into a folder called "Random Signatures" in your Preferences folder.
Technical Details
Message-ID: <macdev-126415.14511115042001@senator-bedfellow.mit.edu>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail
References: <8rmjdtcv4ngqtjnbci7gbq1vg7tjmlqh6r@4ax.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109d41,9c99f778156ee068
X-Google-Attributes: gid109d41,public
X-Google-Thread: 10baa0,9c99f778156ee068
X-Google-Attributes: gid10baa0,public
X-Google-ArrivalTime: 2001-04-15 11:52:12 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail
From: meeroh <macdev@meeroh.org>
Newsgroups: pilot.programmer.codewarrior,codewarrior.palm
Mail-Copies-To: poster
Subject: Re: strange variable behavior
Organization: meeroh.org
References: <8rmjdtcv4ngqtjnbci7gbq1vg7tjmlqh6r@4ax.com>
User-Agent: MT-NewsWatcher/3.1 (PPC)
Date: Sun, 15 Apr 2001 14:51:11 -0400
Message-ID: <macdev-126415.14511115042001@senator-bedfellow.mit.edu>
Lines: 50
NNTP-Posting-Host: TITANIUM-48.MIT.EDU
X-Trace: 987360668 senator-bedfellow.mit.edu 1917 18.101.0.199