亚洲国产日韩欧美在线a乱码,国产精品路线1路线2路线,亚洲视频一区,精品国产自,www狠狠,国产情侣激情在线视频免费看,亚洲成年网站在线观看

嵌入式c語(yǔ)言調(diào)試開(kāi)關(guān)的技巧

時(shí)間:2025-11-27 22:31:23 C語(yǔ)言

嵌入式c語(yǔ)言調(diào)試開(kāi)關(guān)的技巧

  在調(diào)試程序時(shí),經(jīng)常會(huì)用到assert和printf之類(lèi)的函數(shù),我最近做的這個(gè)工程里就有幾百個(gè)assert,在你自認(rèn)為程序已經(jīng)沒(méi)有bug的時(shí)候,就要除去這些調(diào)試代碼,應(yīng)為系統(tǒng)在正常運(yùn)行時(shí)這些用于調(diào)試的信息是無(wú)用的,而且會(huì)占用時(shí)間和空間。怎么刪除呢,以下僅供參考!

  下面給出最簡(jiǎn)單的一種方法:

  #define DEBUG

  #ifdef DEBUG

  #define PRINTF(x) printf x

  #else

  #define PRINTF(x)  ((void)0)

  #endif

  使用時(shí),PRINTF(( "Hello World! " ));

  注意這里是兩個(gè)括號(hào),一個(gè)會(huì)報(bào)錯(cuò)的

  不使用時(shí),直接將"#define DEBUG"屏蔽掉

  另外一個(gè)調(diào)試時(shí)常用的方法是assert,還是在一個(gè)頭文件里,這里用的是STM32函數(shù)庫(kù)的例子

  #ifdef DEBUG 1

  /************************************************************

  * Macro Name : assert_param

  * Description : The assert_param macro is used for function's parameters check.

  * It is used only if the library is compiled in DEBUG mode.

  * Input : - expr: If expr is false, it calls assert_failed function

  * which reports the name of the source file and the source

  * line number of the call that failed.

  * If expr is true, it returns no value.

  * Return : None

  ************************************************************/

  #define assert_param(expr) ((expr) ? (void)0 : assert_failed((u8 *)__FILE__, __LINE__))

  /* Exported functions -------------------------------------*/

  void assert_failed(u8* file, u32 line);

  #else

  #define assert_param(expr) ((void)0)

  #endif/* DEBUG */

  /pic/p>

  #ifdef DEBUG

  /************************************************************

  * Function Name : assert_failed

  * Description : Reports the name of the source file and the source line number

  * where the assert_param error has occurred.

  * Input : - file: pointer to the source file name

  * - line: assert_param error line source number

  * Output : None

  * Return : None

  ************************************************************/

  void assert_failed(u8* file, u32 line)

  {

  /* User can add his own implementation to report the file name and line number,

  ex: printf("Wrong parameters value: file %s on line %d ", file, line) */

  /* Infinite loop */

  while (1){

  }

  }

  #endif

【嵌入式c語(yǔ)言調(diào)試開(kāi)關(guān)的技巧】相關(guān)文章:

嵌入式C語(yǔ)言?xún)?yōu)化技巧03-11

嵌入式C語(yǔ)言?xún)?yōu)化小技巧10-12

嵌入式C語(yǔ)言?xún)?nèi)存操作技巧10-01

C語(yǔ)言中用ASSERT調(diào)試的8大技巧09-03

在C語(yǔ)言中用ASSERT調(diào)試的八個(gè)技巧02-23

C語(yǔ)言中用ASSERT調(diào)試的八大技巧11-07

C語(yǔ)言調(diào)試器是如何工作的01-23

C語(yǔ)言嵌入式編程小知識(shí)01-08

嵌入式C語(yǔ)言編程小知識(shí)11-20