🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: pilot.programmer.codewarrior
2 messages
2 total messages Started by Doug Crocker Sun, 15 Apr 2001 17:40
strange variable behavior
#62
Author: Doug Crocker
Date: Sun, 15 Apr 2001 17:40
27 lines
1642 bytes
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?

thanks in advance
dc

Remove NOSPAM from address to reply via email.
Re: strange variable behavior
#63
Author: 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads