|
首先是要知道條件判斷語(yǔ)句
這個(gè)運(yùn)算符分成三部分:
(條件) ? (條件成立執(zhí)行部分) :(條件不成立執(zhí)行部分)
就這么簡(jiǎn)單例如:a=(x>y ? x:y); 當(dāng)x>y為真時(shí),a=x,當(dāng)x>y為假(即y>x)時(shí),a=y。
不少人問(wèn)在ST官方的STM32的庫(kù)函數(shù)里有很多assert_param是什么作用
比如下面的
assert_param(IS_ADC_ALL_PERIPH(ADCx));
assert_param(IS_ADC_IT(ADC_IT));
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
這樣的函數(shù),幾乎是帶參數(shù)的函數(shù)前面都有調(diào)用assert_param
實(shí)際這是個(gè)調(diào)試函數(shù),當(dāng)你在調(diào)試程序時(shí)打開(kāi)DEBUG參數(shù)assert_param才起作用。
assert_param是反映參數(shù)你在調(diào)用庫(kù)函數(shù)傳遞的參數(shù)是錯(cuò)誤的。
assert_param的原型定義在stm32f10x_conf.h 文件里
定義如下:
#ifdef DEBUG
#define assert_param(expr)((expr) ? (void)0 : assert_failed((u8 *)__FILE__,__LINE__))
void assert_failed(u8* file,u32 line);
#else
#define assert_param(expr)((void)0)
#endif
#endif
可以看到assert_param實(shí)際在DEBUG打開(kāi)時(shí)就是assert_failed,關(guān)閉DEBUG時(shí)是空函數(shù)
assert_failed函數(shù)如下
#ifdef DEBUG
void assert_failed(u8* file, u32 line)
{
//用戶可以在這里添加錯(cuò)誤信息:比如打印出出錯(cuò)的文件名和行號(hào)
while (1)
{
}
}
#endif
|
|