Caffe源码分析——CHECK宏方法

本文详细解析了GLOG库中的CHECK宏,包括CHECK_EQ、CHECK_LE等方法的源码实现及其功能。通过分析宏定义及其实现过程,帮助读者理解如何在C++中进行断言检查。

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

写读Blob源码的时候,读完blob.hpp后,发现其中存在如下的这些方法。下面我们详细的来分析这些方法的源码以及它们的函数功能。

  • CHECK_EQ()
  • CHECK_LE()
  • CHECK_GE()
  • CHECK_LT()

CHECK方法是封装在GLOG库中,而GLOG库是Google开发的用于记录应用程序的使用库,提供基于C++标准输入输出流形式的接口,记录时可以选择不同的日志级别,方便将重要日志和普通日志分开。 GLOG 提供如下的CHECK方法:

代码位于 /usr/include/glog/logging.h

// Equality/Inequality checks - compare two values, and log a FATAL message
// including the two values when the result is not as expected.  The values
// must have operator<<(ostream, ...) defined.
//
// You may append to the error message like so:
//   CHECK_NE(1, 2) << ": The world must be ending!";
//
// We are very careful to ensure that each argument is evaluated exactly
// once, and that anything which is legal to pass as a function argument is
// legal here.  In particular, the arguments may be temporary expressions
// which will end up being destroyed at the end of the apparent statement,
// for example:
//   CHECK_EQ(string("abc")[1], 'b');
//
// WARNING: These don't compile correctly if one of the arguments is a pointer
// and the other is NULL. To work around this, simply static_cast NULL to the
// type of the desired pointer.

#define CHECK_EQ(val1, val2) CHECK_OP(_EQ, ==, val1, val2) #相当于assert(val1 == val2)
# release下可用
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值