【发布时间】:2012-04-02 13:52:35
【问题描述】:
为什么我会在“BIO_flush(b64);”行收到此警告消息“警告:未使用计算的值”我怎样才能摆脱它?
unsigned char *my_base64(unsigned char *input, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
unsigned char *buff = (unsigned char *)malloc(bptr->length+1);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;
BIO_free_all(b64);
return buff;
}
【问题讨论】:
-
BIO_flush()可能已声明返回某些内容,但您没有将结果存储在任何地方或在表达式中使用。 -
BIO_flush() 将被声明为计算值的宏。因为结果未分配给变量,您将收到此警告。我认为如果 BIO_flush 是一个真正的函数,则不会出现此警告。我认为为了避免 -Wall 下的警告,您需要分配给一个临时的
-
BIO_flush也可以是扩展为带有逗号运算符的表达式的宏,其中逗号运算符的左侧没有副作用。不过,如果没有看到BIO_flush的定义,这一切都只是猜测。
标签: c++ warnings gcc-warning