Nested Functions

JavaScript嵌套函数限制
本文介绍了JavaScript中嵌套函数的定义限制,指出它们只能位于顶级作用域内而不能出现在if语句或循环体内。此外,文章还对比了不同实现间的差异,并解释了函数表达式可以在任意位置使用。

Nested functions may be defined only at the top level of the function within which they are nested. That
is, they may not be defined within statement blocks, such as the body of an if statement or while
loop.[*] Note that this restriction applies only to functions defined with the function statement . Function
literal expressions, which are described in the next section, may appear anywhere.


[*] Different implementations of JavaScript may be more relaxed about function definitions than the standard requires. For example,
Netscape's implementation of JavaScript 1.5 allows "conditional function definitions" that appear within if statements.

====================[ 构建 | PS2 | Debug-STM32 ]================================== C:\ST\STM32CubeCLT_1.19.0\CMake\bin\cmake.exe --build D:\STM32Project\PS2\cmake-build-debug-stm32 --target PS2 -j 14 [1/2] Building C object CMakeFiles/PS2.dir/Core/Src/freertos.c.obj D:/STM32Project/PS2/Core/Src/freertos.c: In function 'StartDefaultTask': D:/STM32Project/PS2/Core/Src/freertos.c:135:11: warning: unused variable 'Key1' [-Wunused-variable] 135 | uint8_t Key1=0; | ^~~~ D:/STM32Project/PS2/Core/Src/freertos.c:130:29: warning: unused parameter 'argument' [-Wunused-parameter] 130 | void StartDefaultTask(void *argument) | ~~~~~~^~~~~~~~ D:/STM32Project/PS2/Core/Src/freertos.c: In function 'StartTask02': D:/STM32Project/PS2/Core/Src/freertos.c:196:3: warning: ISO C forbids nested functions [-Wpedantic] 196 | void get_ps2_joystick(int* x, int* y) | ^~~~ D:/STM32Project/PS2/Core/Src/freertos.c:208:3: warning: ISO C forbids nested functions [-Wpedantic] 208 | void set_motor_speed(Motor_Controller* motor, int speed) { | ^~~~ D:/STM32Project/PS2/Core/Src/freertos.c: In function 'set_motor_speed': D:/STM32Project/PS2/Core/Src/freertos.c:209:13: warning: implicit declaration of function 'constrain' [-Wimplicit-function-declaration] 209 | speed = constrain(speed, -100, 100); | ^~~~~~~~~ D:/STM32Project/PS2/Core/Src/freertos.c:226:5: warning: ISO C forbids nested functions [-Wpedantic] 226 | void mecanum_calc(int x, int y, int* rf, int* lf, int* rb, int* lb) { | ^~~~ D:/STM32Project/PS2/Core/Src/freertos.c: In function 'StartTask02': D:/STM32Project/PS2/Core/Src/freertos.c:253:5: warning: implicit declaration of function 'mecanum_calc' [-Wimplicit-function-declaration] 253 | mecanum_calc(joy_x, joy_y, &rf_speed, &lf_speed, &rb_speed, &lb_speed); | ^~~~~~~~~~~~ D:/STM32Project/PS2/Core/Src/freertos.c:182:19: warning: unused variable 'lb' [-Wunused-variable] 182 | int rf, lf, rb, lb; | ^~ D:/STM32Project/PS2/Core/Src/freertos.c:182:15: warning: unused variable 'rb' [-Wunused-variable] 182 | int rf, lf, rb, lb; | ^~ D:/STM32Project/PS2/Core/Src/freertos.c:182:11: warning: unused variable 'lf' [-Wunused-variable] 182 | int rf, lf, rb, lb; | ^~ D:/STM32Project/PS2/Core/Src/freertos.c:182:7: warning: unused variable 'rf' [-Wunused-variable] 182 | int rf, lf, rb, lb; | ^~ D:/STM32Project/PS2/Core/Src/freertos.c:181:14: warning: unused variable 'joy_y' [-Wunused-variable] 181 | int joy_x, joy_y; | ^~~~~ D:/STM32Project/PS2/Core/Src/freertos.c:181:7: warning: unused variable 'joy_x' [-Wunused-variable] 181 | int joy_x, joy_y; | ^~~~~ D:/STM32Project/PS2/Core/Src/freertos.c:177:24: warning: unused parameter 'argument' [-Wunused-parameter] 177 | void StartTask02(void *argument) | ~~~~~~^~~~~~~~ D:/STM32Project/PS2/Core/Src/freertos.c: At top level: D:/STM32Project/PS2/Core/Src/freertos.c:226:10: warning: 'mecanum_calc' defined but not used [-Wunused-function] 226 | void mecanum_calc(int x, int y, int* rf, int* lf, int* rb, int* lb) { | ^~~~~~~~~~~~ D:/STM32Project/PS2/Core/Src/freertos.c:196:8: warning: 'get_ps2_joystick' defined but not used [-Wunused-function] 196 | void get_ps2_joystick(int* x, int* y) | ^~~~~~~~~~~~~~~~ [2/2] Linking CXX executable PS2.elf FAILED: PS2.elf C:\WINDOWS\system32\cmd.exe /C "cd . && C:\ST\STM32CubeCLT_1.19.0\GNU-tools-for-STM32\bin\arm-none-eabi-g++.exe -mcpu=cortex-m3 -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections -O0 -g3 -fno-rtti -fno-exceptions -fno-threadsafe-statics -g -mcpu=cortex-m3 -T "D:/STM32Project/PS2/STM32F103C8Tx_FLASH.ld" --specs=nano.specs -Wl,-Map=PS2.map -Wl,--gc-sections -Wl,--start-group -lc -lm -Wl,--end-group -Wl,--print-memory-usage -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group CMakeFiles/PS2.dir/Task/src/contralTask.cpp.obj CMakeFiles/PS2.dir/Task/src/decodeTask.cpp.obj CMakeFiles/PS2.dir/PS2/src/PS2.c.obj CMakeFiles/PS2.dir/bsp/src/bsp.cpp.obj CMakeFiles/PS2.dir/Core/Src/main.c.obj CMakeFiles/PS2.dir/Core/Src/gpio.c.obj CMakeFiles/PS2.dir/Core/Src/freertos.c.obj CMakeFiles/PS2.dir/Core/Src/tim.c.obj CMakeFiles/PS2.dir/Core/Src/stm32f1xx_it.c.obj CMakeFiles/PS2.dir/Core/Src/stm32f1xx_hal_msp.c.obj CMakeFiles/PS2.dir/Core/Src/stm32f1xx_hal_timebase_tim.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c.obj CMakeFiles/PS2.dir/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c.obj CMakeFiles/PS2.dir/Core/Src/system_stm32f1xx.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/croutine.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/event_groups.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/list.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/queue.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/tasks.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/timers.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c.obj CMakeFiles/PS2.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM3/port.c.obj CMakeFiles/PS2.dir/Core/Src/sysmem.c.obj CMakeFiles/PS2.dir/Core/Src/syscalls.c.obj CMakeFiles/PS2.dir/startup_stm32f103xb.s.obj -o PS2.elf && cd ." C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/PS2.dir/Core/Src/tim.c.obj:D:/STM32Project/PS2/Core/Src/tim.c:28: multiple definition of `htim3'; CMakeFiles/PS2.dir/Core/Src/freertos.c.obj:D:/STM32Project/PS2/Core/Src/freertos.c:46: first defined here C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/PS2.dir/Core/Src/stm32f1xx_hal_timebase_tim.c.obj:D:/STM32Project/PS2/Core/Src/stm32f1xx_hal_timebase_tim.c:28: multiple definition of `htim4'; CMakeFiles/PS2.dir/Core/Src/freertos.c.obj:D:/STM32Project/PS2/Core/Src/freertos.c:46: first defined here C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: warning: PS2.elf has a LOAD segment with RWX permissions C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/PS2.dir/Core/Src/freertos.c.obj: in function `StartTask02': D:/STM32Project/PS2/Core/Src/freertos.c:253:(.text.StartTask02+0x100): undefined reference to `mecanum_calc' C:/ST/STM32CubeCLT_1.19.0/GNU-tools-for-STM32/bin/../lib/gcc/arm-none-eabi/13.3.1/../../../../arm-none-eabi/bin/ld.exe: CMakeFiles/PS2.dir/Core/Src/freertos.c.obj: in function `set_motor_speed': D:/STM32Project/PS2/Core/Src/freertos.c:209:(.text.set_motor_speed.0+0x1c): undefined reference to `constrain' Memory region Used Size Region Size %age Used RAM: 8464 B 20 KB 41.33% FLASH: 22284 B 64 KB 34.00% collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
最新发布
10-22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值