Hi Dave, You must use: controls.slRelease = (long) 200 * SCALEFACTOR; or controls.slRelease = 200 * (long) SCALEFACTOR; otherwise the compiler thinks that you mean: controls.slRelease = (long) (int) (200 * SCALEFACTOR) ; // Sorry I forgot ( ) in my first E-mail that delivers: (long) (int) 50000 that is: (long) -15536 in your special case (there will yet be no overflow) you can also use (but I don't advice it): controls.slRelease = (long) (unsigned) (200 * SCALEFACTOR); kind regards, Wim de Haan Exendis B.V. W.J. de Haan P.O.box 56, 6710 BB Ede Keesomstraat 4, 6716 AB Ede The Netherlands. Tel: +31-(0)318 - 676305 Fax: +31-(0)318 - 676319 mailto: URL: http://www.exendis.com <http://www.exendis.com/ -----Original Message----- From: dtw_aerie [mailto:] Sent: zondag 11 januari 2004 22:58 To: Subject: [motoroladsp] Unexpected compiler result for maths on a long data type Hi, I wonder if someone can help me. I'm pretty new to Codewarrior and the 56000, but am an experienced C programmer so I'm not completely clueless. However, I'm getting some behaviour from the compiler which seems a bit odd to me. I have a structure, one member of which is a long. I'm setting this to an initialisation value near the start of my program. This value is a constant multiplied by a Scaling factor, which I'm currently experimenting with. The scaling value is set by use of a #define in a header file. Its value is currently set to 250. So I have a line of code as follows: controls.slRelease = 200 * SCALEFACTOR; I was expecting the value of controls.slRelease to be 50,000, but it isn't - it's -15536. Looking at the assembly produced by the compiler, I get: 0x0000004C 0x86F40000C350 movei #-15536,X:0x0000 0x0000004F 0x86F40000FFFF movei #-1,X:0x0000 Looking at how longs are stored in memory, the first line of this, setting the low order word, is correct. The high order word, however, has been set to 0xFFFF, which isn't what I was expecting at all. To check, I got rid of the #define: controls.slRelease = 200 * 250; which produces the same compiler output. As a further test I wrote the value to the variable directly: controls.slRelease = 50000; The compiler produced the following: 0x00000052 0x86F40000C350 movei #-15536,X:0x0000 0x00000055 0x86F400000000 movei #0,X:0x0000 whch shows up as my expected value of 50,000. It seems that the compiler is treating the high order word in these cases differently. Is this what is happening, and if so why - what have I missed? Or have I found a bug? Thanks for your time Dave Falconer |