断言
来源:互联网 发布:淘宝 618 大促 销售额 编辑:程序博客网 时间:2024/06/11 06:23
1.什么是断言?
断言是编程术语,表示为一些布尔表达式,程序员相信在程序中的某个特定点该表达式值为真,可以在任何时候启用和禁用断言验证,因此可以在测试时启用断言而在部署时禁用断言。同样,程序投入运行后,最终用户在遇到问题时可以重新启用断言。—来自百度。
2.举例子;
/* Exported macro ————————————————————*/
ifdef USE_FULL_ASSERT
/**
* @brief The assert_param macro is used for function’s parameters check.
* @param 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.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)FILE, LINE))
/* Exported functions ——————————————————- */
void assert_failed(uint8_t* file, uint32_t line);
else
#define assert_param(expr) ((void)0)
endif /* USE_FULL_ASSERT */
endif /* __STM32F10x_CONF_H */
这是stm32里面的断言宏定义:
很简单 。意思是说:打开USE_FULL_ASSERT 时,使用assert_param ,不打开始时,不用断言,即用((void)0)代替,这个可以认为没有什么意义,但是不影响程序的运行。
举例子:
/* Check the parameters */
assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
typedef enum//枚举
{
GPIO_Speed_10MHz = 1,
GPIO_Speed_2MHz,
GPIO_Speed_50MHz
}GPIOSpeed_TypeDef;
define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || `((SPEED) == GPIO_Speed_50MHz)) 不是真就是假
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz,类型需要匹配
GPIO_InitTypeDef GPIO_InitStructure;
/**
* @brief GPIO Init structure definition
*/
typedef struct
{
uint16_t GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
This parameter can be any value of @ref GPIO_pins_define */
GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
This parameter can be a value of @ref GPIOSpeed_TypeDef */
GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
This parameter can be a value of @ref GPIOMode_TypeDef */
}GPIO_InitTypeDef;
明白了吧
当然这只是讲的在32中的一点应用,在内核及其他的工程调试中也和这样的原理差不多 。。。
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- 断言
- ubuntu安装机器学习环境
- 强制类型转换运算符的优先级
- Python爬虫0.1
- Python爬虫0.2
- python爬虫0.3
- 断言
- python0.4
- 初学nlp&nn
- 《Machine Learning in&…
- windows下多进程通信,基于共享内存环形队列实现
- 华为2017.8月笔试题
- H5多图片压缩加水印上传
- 欢迎使用CSDN-markdown编辑器
- 【机器学习基础】准确率(Accuracy), 精确率(Precision), 召回率(Recall)和F1-Measure