Article View: comp.sys.mac.programmer.codewarrior
Article #855Re: Long long, optimization and weird debugger errors
From: MW Ron
Date: Wed, 29 Jan 2003 20:56
Date: Wed, 29 Jan 2003 20:56
107 lines
3901 bytes
3901 bytes
In article <iwXX9.1384$Xh6.582263850@newssvr13.news.prodigy.com>,
"Raymond" <ray@n0.sp4m.powerproduction.n0.sp4m.com> wrote:
>Jason
>
>I had a similar problem and MW support tried to pacify me by saying I was
>doing something wrong, and finally blew me off.
>-- (MWRon, see: MW Tech support # 1-28735400)
I looked into this and support thought that you had understood the
question. Here is a fuller description of why this is not an error and
your code is non conformant.
Ron
a left shift, can only operate in the context of the bits in the
part being shifted. So shifting a 32-bit value by a value of 32
or greater is undefined in the language standard.
a constant like 5, is an int and will not get promoted to
a "long long" or "unsigned long long" unless the code explicitly
uses the long long (or unsigned long long) form of the constant:
5LL or 5ULL
or if there is an explicit type casting:
(long long) 5 or (unsigned long long) 5
When assigning a computation to a variable the implicit type convert
happens after the expression is evaluated.
so on PowerPC:
(5 << 32) | (32777)
produces either: 0x8009 or 0x800d
In the first case the IR optimizer treated the undefined value
as 0 (5 << 32) == 0. In the second case the code generator ANDed
the shift amount with 31 such that (5 << 32) becomes (5 << 0) == 5.
It will never produce 0x500008009, and even then the example
is wrong as 0x500008009 & 0xFFFF000000000000 produces 0.
Neither behavior will produce the results expected by the code
example:
void main ( void )
{
UInt64 value;
value = ( ( 5 << 32 ) | ( 32777 ) );
Routine_1( value );
}
void Routine_1 ( UInt64 value )
{
Routine_2( value );
}
void Routine_2 ( UInt64 value )
{
if( value & 0xFFFF000000000000 )
{
return; //no problems
}
else
{
complain(__LINE__);
}
}
therefore your code must be written like:
void main ( void )
{
UInt64 value;
value = ( ( ((UInt64)5) << 32 ) | ( 32777 ) );
Routine_1( value );
}
void Routine_1 ( UInt64 value )
{
Routine_2( value );
}
void Routine_2 ( UInt64 value )
{
if( value & 0xFFFFFFFF00000000 )
{
return; //no problems
}
else
{
complain(__LINE__);
}
}
--
Free Programming Courses at CodeWarrior U
<http://www.codewarrioru.com>
Metrowerks, maker of CodeWarrior - "Software Starts Here"
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com
Technical Details
Message-ID:
<mwron-AEB1B3.15564629012003@enews.newsguy.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!mwronReferences:
<BA54E438.7596%jbotwick@nc.rr.com> <iwXX9.1384$Xh6.582263850@newssvr13.news.prodigy.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f635e,9970b840368bc3e
X-Google-Attributes: gidf635e,public
X-Google-Thread: 10bcce,9970b840368bc3e
X-Google-Attributes: gid10bcce,public
X-Google-Thread: fd047,9970b840368bc3e
X-Google-Attributes: gidfd047,public
X-Google-ArrivalTime: 2003-01-29 13:20:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!mwron
From: MW Ron <mwron@metrowerks.com>
Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac,codewarrior.windows
Subject: Re: Long long, optimization and weird debugger errors
Date: Wed, 29 Jan 2003 15:56:46 -0500
Organization: Metrowerks
Lines: 107
Message-ID: <mwron-AEB1B3.15564629012003@enews.newsguy.com>
References: <BA54E438.7596%jbotwick@nc.rr.com> <iwXX9.1384$Xh6.582263850@newssvr13.news.prodigy.com>
NNTP-Posting-Host: p-183.newsdawg.com
User-Agent: MT-NewsWatcher/3.2 (PPC Mac OS X)
X-Face: )mY~XFHLw)UOW!W#[Ljvxq6Ja7(g'#F0-g*&puNxR8hEJkd@Oue/70^.)I78\
(%a%&Id211u"l/t.llWo/M|?15XUlx9!IGkdWiEmcasiyg"k;Q9[~XuE+`t2"*n(>nmm
@L/q,TjMd5+H{gASEPDR^$