欧美日韩不卡一区二区三区,www.蜜臀.com,高清国产一区二区三区四区五区,欧美日韩三级视频,欧美性综合,精品国产91久久久久久,99a精品视频在线观看

C語言

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

時間:2025-01-24 09:48:39 C語言 我要投稿
  • 相關(guān)推薦

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

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

  下面給出最簡單的一種方法:

  #define DEBUG

  #ifdef DEBUG

  #define PRINTF(x) printf x

  #else

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

  #endif

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

  注意這里是兩個括號,一個會報錯的

  不使用時,直接將"#define DEBUG"屏蔽掉

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

  #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 */

  //assert_failed此函數(shù)要自己定義

  #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語言調(diào)試開關(guān)的技巧】相關(guān)文章:

嵌入式C語言優(yōu)化技巧10-27

嵌入式C語言內(nèi)存操作技巧07-25

嵌入式C語言優(yōu)化小技巧09-09

C語言中用ASSERT調(diào)試的8大技巧06-26

C語言中用ASSERT調(diào)試的八大技巧06-18

在C語言中用ASSERT調(diào)試的八個技巧11-11

C語言調(diào)試器是如何工作的10-06

嵌入式C語言編程小知識12-20

嵌入式C語言編程知識總結(jié)06-04