这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » unsigned,int 【求助】宏定义时溢出,想用unsigned int,怎

共2条 1/1 1 跳转至

unsigned,int 【求助】宏定义时溢出,想用unsigned int,怎么办?

院士
2006-09-17 18:14:16     打赏
unsigned,int 【求助】宏定义时溢出,想用unsigned int,怎么办?



关键词: unsigned     求助     定义     溢出     想用     怎么办    

院士
2006-12-22 22:43:00     打赏
2楼
问 宏定义时溢出,想用unsigned int,怎么办?
============================================================
有如下一句定义:
#define TIMER_A_50 (750*50) // 50ms
程序中有:
CCR0 = TIMER_A_50; // 50ms
============================================================
IAR C/C++ Compiler for MSP430
V3.20A/W32 [Kickstart] (3.20.1.3)
编译器报警告:
Warning[Pe061]: integer operation result is out of range
Warning[Pe068]: integer conversion resulted in a change of sign
============================================================
而实际上750*50=37500 < 65535,实在是不解,怎么解决此问题呢? 1: 1种情况:
当改为#define TIMER_A_50 (37500) // 50ms
编译没有警告了。
2种情况:
改为CCR0 = 750*50; // 50ms
警告依然存在。
3种情况:
改为CCR0 = 37500; // 50ms
没有警告出现。
-----------------------------
现在演变成给unsigned int数赋值时750*50就二条警告,而直接用37500就正常,
WHY?谁给个合理的解释?
-----------------------------
我用是编译器是:
IAR Assembler for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\a430.exe
2004-6-15 15:59:34, 491520 bytes

IAR C/C++ Compiler for MSP430
V3.20A/W32 [Kickstart] (3.20.1.3)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\icc430.exe
2004-6-15 15:58:08, 5623808 bytes

IAR Build
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\iarbuild.exe
2004-6-10 9:20:26, 14848 bytes

IAR Embedded Workbench IDE
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\iaridepm.exe
2004-6-9 22:39:20, 729088 bytes

IAR Library Builder
1.03K (1.3.11.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\xar.exe
2004-6-9 17:31:22, 98304 bytes

IAR XLIB
3.29H/386 (3.29.0.8)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\xlib.exe
2004-6-9 17:31:22, 421888 bytes

IAR XLINK
4.59A (4.59.1.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\xlink.exe
2004-6-4 16:18:44, 1183744 bytes

IAR CSpyBat
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\cspybat.exe
2004-6-9 2002, 131072 bytes

IAR Project File Converter for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\cwtd430.dll
2004-6-16 832, 352256 bytes

IAR Workbench Target Descriptor for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\swtd430.dll
2004-6-22 15:10:52, 507904 bytes

IAR C-SPY Batch Simulator Driver for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\430bat.dll
2004-6-18 9:51:22, 118784 bytes

IAR C-SPY Library Support Plug-in for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\430libsupport.dll
2004-6-18 9:51:38, 225280 bytes

IAR C-SPY Processor Descriptor for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\430proc.dll
2004-6-21 11:36:00, 1036288 bytes

IAR C-SPY Simulator Driver for MSP430
V3.20A/W32 [Kickstart] (3.20.1.3)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\430sim.dll
2004-6-23 18:49:20, 692224 bytes

IAR Workbench Target Descriptor, Simulator, for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\swtd430sim.dll
2004-6-22 1532, 155648 bytes

IAR C-SPY Emulator Driver for MSP430
V3.20D/W32 [Kickstart] (3.20.4.3)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\430fet.dll
2004-8-3 20:34:06, 507904 bytes

HIL
1, 0, 1, 2 (1.0.1.2)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\hil.dll
2004-3-3 15:58:18, 28672 bytes

MSP430
1, 1, 4, 6 (1.1.4.6)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\JLink430.dll
2004-6-23 14:44:54, 25600 bytes

MSP430
1, 1, 6, 5 (1.1.6.5)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\MSP430.dll
2004-7-30 9:50:18, 53248 bytes

IAR Workbench Target Descriptor, Emulator, for MSP430
V3.20A/W32 (3.20.1.9)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\bin\swtd430fet.dll
2004-6-22 1504, 204800 bytes

LCD Plugin
3.20A (3.2.0.1)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\plugins\Lcd\lcd.dll
2004-6-21 11:18:10, 118784 bytes

Stack Plugin
2.31A (2.3.1.1)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\430\plugins\Stack\stack.dll
2004-6-17 9:36:24, 184320 bytes

IAR Find In Files
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\findinfiles.dll
2004-6-10 950, 49152 bytes

IAR IDE Framework
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\ideframework.dll
2004-6-9 19:29:52, 335872 bytes

IAR Log Window
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\logwindow.dll
2004-6-10 9:05:02, 131072 bytes

MFCDLL Shared Library - Retail Version
7.10.3077.0 (7.10.3077.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\mfc71.dll
2004-6-10 9:28:00, 1060864 bytes

Microsoft? C++ Runtime Library
7.10.3077.0 (7.10.3077.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\msvcp71.dll
2004-6-10 9:28:02, 499712 bytes

Microsoft? C Runtime Library
7.10.3052.4 (7.10.3052.4)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\msvcr71.dll
2004-6-10 9:28:04, 348160 bytes

IAR Project Manager Engine
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\projectmanagerengine.dll
2004-6-9 22:28:42, 827392 bytes

IAR Project Manager Gui
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\projectmanagergui.dll
2004-6-9 22:52:22, 520192 bytes

IAR Text Editor
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\texteditor.dll
2004-6-9 21:18:38, 327680 bytes

Shared Library for Xerces-C Version 1.5.1
1, 5, 1 (1.5.1.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\xerces-c_1_5_1.dll
2004-6-9 18:40:50, 1175552 bytes

IAR C-SPY Debugger GUI
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\debuggergui.dll
2004-6-11 14:39:20, 819200 bytes

IAR C-SPY Debugger Kernel
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\bin\kernel.dll
2004-6-11 12:22:28, 1015808 bytes

IAR Code Coverage Plug-in
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\plugins\CodeCoverage\codecoverage.dll
2004-6-9 19:57:48, 167936 bytes

IAR Profiling Plug-in
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\plugins\Profiling\profiling.dll
2004-6-9 21:00:58, 155648 bytes

IAR Trace Plug-in
4.3 (4.3.0.0)
C:\Program Files\IAR Systems\Embedded Workbench 4.0\common\plugins\Trace\trace.dll
2004-6-9 21:27:08, 233472 bytes 2: 怎么就没人给个合理的解释啊 3: 哈,很明显,赋值前,750×50是作为有符号整数来计算,当然溢出了,改为750u×50u(强制为无符号)就是无符号的计算了,一切OK。。。。

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]