SCRIPT5042: Variable undefined in strict mode

本文强调在严格模式下,定义变量必须使用var关键字。避免直接赋值,如userObj=item.userObj; 应改为 var userObj=item.userObj; 以确保代码规范性和可读性。

这个问题是在严格模式下,定义变量时要写明var

例如 

userObj = item.userObj;  在这种情况下就是错的,要记得先申明。

var userObj = item.userObj; 这样就可以了

*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'Main' compiling stm32f10x_it.c... compiling conn.c... ..\conn.c(20): warning: #177-D: variable "can_box" was declared but never referenced CAN_FIFOMailBox_TypeDef *can_box; ..\conn.c: 1 warning, 0 errors compiling cfg_value.c... compiling updata.c... ..\updata.c(78): warning: #177-D: variable "add" was declared but never referenced uint32_t add,file_flag; ..\updata.c(78): warning: #177-D: variable "file_flag" was declared but never referenced uint32_t add,file_flag; ..\updata.c: 2 warnings, 0 errors compiling main.c... ..\main.c(87): warning: #1296-D: extended constant initialiser used {0,(u32)motor_step_cmd_demo}, ..\main.c(88): warning: #1296-D: extended constant initialiser used {0,(u32)cfg_write_buf}, ..\main.c(94): warning: #177-D: variable "status" was declared but never referenced static u8 status=0; ..\main.c: 3 warnings, 0 errors compiling IO.c... compiling HardWare.c... ..\HardWare.c(162): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG2_GPIO, TEP_CFG2_PIN,val&1); ..\HardWare.c(163): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG3_GPIO, TEP_CFG3_PIN,(val>>1)&1); ..\HardWare.c(164): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG4_GPIO, TEP_CFG4_PIN,(val>>1)&1); ..\HardWare.c(501): warning: #111-D: statement is unreachable if ((CAN1->TSR&CAN_TSR_TME2) != CAN_TSR_TME2) ..\HardWare.c: 4 warnings, 0 errors compiling misc.c... compiling stm32f10x_gpio.c... compiling stm32f10x_crc.c... compiling stm32f10x_flash.c... compiling motor.c... ..\motor.c(486): warning: #177-D: variable "i" was declared but never referenced uint32_t i,time_run; ..\motor.c(487): warning: #177-D: variable "ptr16" was declared but never referenced uint16_t *ptr16,ad_val; //最大4096 *10 不会超过16位 ..\motor.c(854): warning: #177-D: variable "i" was declared but never referenced uint32_t i,time_run; ..\motor.c(1381): error: #20: identifier "va_list" is undefined va_list args; ..\motor.c(1382): warning: #223-D: function "va_start" declared implicitly va_start(args, fmt); ..\motor.c(1384): warning: #223-D: function "va_end" declared implicitly va_end(args); ..\motor.c(1520): error: #268: declaration may not appear after executable statement in block long pulses = GetMotorStepPos(); ..\motor.c(1522): error: #268: declaration may not appear after executable statement in block uint32_t calc_temp = pulses * MM_Y_ROUND; ..\motor.c(1524): error: #268: declaration may not appear after executable statement in block uint32_t cur_mm10 = calc_temp / STEP_Y_ROUND; ..\motor.c(1429): warning: #546-D: transfer of control bypasses initialization of: variable "pulses" (declared at line 1520) variable "calc_temp" (declared at line 1522) variable "cur_mm10" (declared at line 1524) switch(m->mode) ^ ..\motor.c: 6 warnings, 4 errors compiling stm32f10x_rcc.c... compiling stm32f10x_can.c... compiling stm32f10x_spi.c... compiling stm32f10x_usart.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_adc.c... compiling stm32f10x_exti.c... compiling stm32f10x_dma.c... compiling stm32f10x_tim.c... assembling startup_stm32f10x_md.s... compiling core_cm3.c... compiling stm32f10x_iwdg.c... compiling system_stm32f10x.c... ".\obj\ir_12.axf" - 4 Error(s), 16 Warning(s). Target not created. Build Time Elapsed: 00:00:06 帮我看一下运行报错的信息
最新发布
09-02
*** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\Keil_v5\ARM\ARMCC\Bin' Build target 'Target 1' compiling LightSensor.c... Hardware\LightSensor.c(2): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\LightSensor.c: 0 warnings, 1 error compiling LED.c... Hardware\LED.c(37): error: #20: identifier "KEY_S0" is undefined if(key_val == KEY_S0) { Hardware\LED.c(38): warning: #188-D: enumerated type mixed with another type flowMode = (flowMode + 1) % 3; Hardware\LED.c(53): error: #20: identifier "KEY_S1" is undefined if(key_val == KEY_S1) { Hardware\LED.c(54): warning: #188-D: enumerated type mixed with another type breathState = (breathState + 1) % 3; Hardware\LED.c(75): warning: #223-D: function "HAL_GetTick" declared implicitly if(flowMode != LED_FLOW_OFF && (HAL_GetTick() - lastUpdate > 200)) { Hardware\LED.c(93): warning: #223-D: function "HAL_GetTick" declared implicitly if(breathState == BREATH_ON && (HAL_GetTick() - lastUpdate > 10)) { Hardware\LED.c(34): warning: #177-D: variable "flowDir" was declared but never referenced static uint8_t flowDir = 0; // 0:宸︹啋鍙? 1:鍙斥啋宸? Hardware\LED.c: 5 warnings, 2 errors compiling OLED.c... Hardware\OLED.c(3): error: #5: cannot open source input file "light_sensor.h": No such file or directory #include "light_sensor.h" Hardware\OLED.c: 0 warnings, 1 error compiling PWM.c... Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; Hardware\PWM.c(25): error: #20: identifier "LED1_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED2_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED3_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED4_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED5_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED6_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(25): error: #20: identifier "LED7_PIN" is undefined GPIO_ResetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED1_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED2_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED3_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED4_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED5_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED6_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c(31): error: #20: identifier "LED7_PIN" is undefined GPIO_SetBits(LED_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN | LED6_PIN | LED7_PIN); Hardware\PWM.c: 0 warnings, 21 errors compiling Buzzer.c... Hardware\Buzzer.c(28): error: #20: identifier "KEY_S2" is undefined if(key_val == KEY_S2) { Hardware\Buzzer.c(36): warning: #223-D: function "HAL_GetTick" declared implicitly if(buzzerState && (HAL_GetTick() - lastToggle > 500)) { Hardware\Buzzer.c(38): warning: #223-D: function "GPIO_ToggleBits" declared implicitly GPIO_ToggleBits(BUZZER_PORT, BUZZER_PIN); // 鍒囨崲鐘舵€? Hardware\Buzzer.c: 2 warnings, 1 error compiling main.c... .\Hardware\common.h(6): error: #101: "RESET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #101: "SET" has already been declared in the current scope typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "FlagStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(6): error: #256: invalid redeclaration of type name "ITStatus" (declared at line 519 of ".\Start\stm32f10x.h") typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus; .\Hardware\common.h(8): error: #101: "DISABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #101: "ENABLE" has already been declared in the current scope typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; .\Hardware\common.h(8): error: #256: invalid redeclaration of type name "FunctionalState" (declared at line 521 of ".\Start\stm32f10x.h") typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; User\main.c(22): warning: #223-D: function "delay_init" declared implicitly delay_init(); // 寤舵椂鍒濆鍖? User\main.c(27): error: #165: too few arguments in function call LightSensor_Init(); User\main.c(31): error: #140: too many arguments in function call u8 key = KEY_Scan(0); // 涓嶆敮鎸佽繛鎸? User\main.c(34): error: #20: identifier "KEY0_PRES" is undefined if (key == KEY0_PRES) User\main.c(37): warning: #223-D: function "LED_Flow_SetMode" declared implicitly LED_Flow_SetMode(sysState.ledFlowMode); User\main.c(41): error: #20: identifier "KEY1_PRES" is undefined if (key == KEY1_PRES) User\main.c(46): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_ON); User\main.c(46): error: #20: identifier "LED_BREATH_ON" is undefined LED_Breath_SetState(LED_BREATH_ON); User\main.c(47): warning: #223-D: function "LED_Breath_SetPeriod" declared implicitly LED_Breath_SetPeriod(500); // 500ms鍛ㄦ湡 User\main.c(52): warning: #223-D: function "LED_Breath_SetState" declared implicitly LED_Breath_SetState(LED_BREATH_OFF); User\main.c(52): error: #20: identifier "LED_BREATH_OFF" is undefined LED_Breath_SetState(LED_BREATH_OFF); User\main.c(57): error: #20: identifier "KEY2_PRES" is undefined if (key == KEY2_PRES) User\main.c(60): warning: #223-D: function "Buzzer_SetState" declared implicitly Buzzer_SetState(sysState.beepState); User\main.c(64): error: #20: identifier "KEY3_PRES" is undefined if (key == KEY3_PRES) User\main.c(69): warning: #223-D: function "OLED_DisplayOn" declared implicitly OLED_DisplayOn(); User\main.c(71): warning: #223-D: function "OLED_ShowPersonalInfo" declared implicitly OLED_ShowPersonalInfo(); User\main.c(75): warning: #223-D: function "OLED_DisplayOff" declared implicitly OLED_DisplayOff(); User\main.c(80): warning: #223-D: function "LED_Flow_Task" declared implicitly LED_Flow_Task(); User\main.c(83): warning: #223-D: function "LED_Breath_Task" declared implicitly LED_Breath_Task(); User\main.c(86): warning: #223-D: function "Buzzer_Task" declared implicitly Buzzer_Task(); User\main.c(91): warning: #223-D: function "OLED_UpdateLightState" declared implicitly OLED_UpdateLightState(); // 鏇存柊鍏夌収鐘舵€佹樉绀? User\main.c(94): warning: #223-D: function "delay_ms" declared implicitly delay_ms(10); User\main.c: 14 warnings, 15 errors ".\Objects\Project.axf" - 41 Error(s), 21 Warning(s). Target not created.
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值