写程序千万不要crl+C/V

本文分享了一次因代码复制粘贴导致的错误排查经历,提醒开发者即使代码功能相同,直接复制并修改变量名也可能引入难以察觉的bug,强调了理解代码逻辑的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有两段功能一模一样的代码,我直接复制粘贴后,完了改变量名... ...

结果就是错误找半天

转载于:https://www.cnblogs.com/YipCharlesLee/p/4350167.html

“/** ****************************(C) COPYRIGHT 2021 DIODE**************************** * @file led_task.c/h * @brief led task, * led灯任务 * @note * @history * Version Date Author Modification * @verbatim ============================================================================== ============================================================================== @endverbatim ****************************(C) COPYRIGHT 2021 DIODE**************************** */ #include "outctl_task.h" #include "struct_typedef.h" // 正确顺序(CMSIS-RTOS必须在FreeRTOS之后) #include "FreeRTOS.h" // 必须最先包含 #include "task.h" // FreeRTOS核心 #include "cmsis_os.h" // CMSIS封装层 extern uint16_t RC_FLAG; uint16_t time_crl; uint8_t rc_flag=0,rc_out_time=20; //num记录离线时间 uint8_t vision_flag=0,vision_out_time=20; //num记录离线时间 bool_t rc_unable_flag=0; uint8_t sw2; extern uint8_t CAN_M3508_Cnt[]; extern uint8_t CAN_M3508_Flag[]; //typedef enum { // osOK = 0, ///< function completed; no error or event occurred. // osEventSignal = 0x08, ///< function completed; signal event occurred. // osEventMessage = 0x10, ///< function completed; message event occurred. // osEventMail = 0x20, ///< function completed; mail event occurred. // osEventTimeout = 0x40, ///< function completed; timeout occurred. // osErrorParameter = 0x80, ///< parameter error: a mandatory parameter was missing or specified an incorrect object. // osErrorResource = 0x81, ///< resource not available: a specified resource was not available. // osErrorTimeoutResource = 0xC1, ///< resource not available within given time: a specified resource was not available within the timeout period. // osErrorISR = 0x82, ///< not allowed in ISR context: the function cannot be called from interrupt service routines. // osErrorISRRecursive = 0x83, ///< function called multiple times from ISR with same object. // osErrorPriority = 0x84, ///< system cannot determine priority or thread has illegal priority. // osErrorNoMemory = 0x85, ///< system is out of memory: it was impossible to allocate or reserve memory for the operation. // osErrorValue = 0x86, ///< value of a parameter is out of range. // osErrorOS = 0xFF, ///< unspecified RTOS error: run-time error but no other error message fits. // os_status_reserved = 0x7FFFFFFF ///< prevent from enum down-size compiler optimization. //} osStatus; osStatus osDelay (uint32_t millisec); //控制模式 eRemoteMode remoteMode = RC; eSystemState systemState = SYSTEM_STARTING; //系统状态 osStatus osDelay (uint32_t millisec) { #if INCLUDE_vTaskDelay TickType_t ticks = millisec / portTICK_PERIOD_MS; vTaskDelay(ticks ? ticks : 1); /* Minimum delay = 1 tick */ return osOK; #else (void) millisec; return osErrorResource; #endif } /** * @brief 失控保护任务,间隔 OUTCTL_TASK_TIME_MS 100ms * @param[in] pvParameters: 空 * @retval none */ void outctl_task(void const *pvParameters) { //空闲一段时间 osDelay(OUTCTL_TASK_INIT_TIME); // uint8_t i=0; while (1) { time_crl++; rc_out_time++; vision_out_time++; CAN_M3508_Cnt[0]++; CAN_M3508_Cnt[1]++; CAN_M3508_Cnt[2]++; CAN_M3508_Cnt[3]++; if(rc_out_time>20) rc_out_time=20; if(rc_out_time>10) rc_flag=0; else rc_flag=1; // for(i=0;i<4;i++) // { // if(CAN_M3508_Cnt[i]>20) // CAN_M3508_Cnt[i]=20; // if(CAN_M3508_Cnt[i]>10) // CAN_M3508_Flag[i]=1; // else CAN_M3508_Flag[i]=0; // client_state_now.CAN_M3508_Flag[i]= CAN_M3508_Flag[i]; // } //系统相对延时 osDelay(OUTCTL_TASK_TIME_MS); } } void RC_unable(void){ rc_unable_flag=1; } void RC_restart(void){ rc_unable_flag=0; } /** * @brief 拨杆模式选择 * @param void * @retval void * @attention 键盘或鼠标,可在此自定义模式选择方式,1ms执行一次 */ //void SYSTEM_UpdateRemoteMode( void ) //{ // if (rc.sw2==1 || rc.sw2==3) // { // remoteMode = RC; // } // else // { // remoteMode = PC; // } //} //返回控制模式 eRemoteMode SYSTEM_GetRemoteMode(void) { return remoteMode; } //返回系统状态 eSystemState SYSTEM_GetSystemState(void) { return systemState; } ”“*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Build target 'Can_Serial' compiling outctl_task.c... linking... Can_Serial\Can_Serial.axf: Error: L6200E: Symbol osDelay multiply defined (by outctl_task.o and cmsis_os.o). Not enough information to list image symbols. Not enough information to list load addresses in the image map. Finished: 2 information, 0 warning and 1 error messages. "Can_Serial\Can_Serial.axf" - 1 Error(s), 0 Warning(s). Target not created. Build Time Elapsed: 00:00:03”现在怎么操作呢
最新发布
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值