简体   繁体   English

我如何解释这个宏?

[英]How can I interpret this macro?

I really wonder what the return value of soap_strcpy is? 我真的想知道soap_strcpy的返回值是多少?

# define soap_strcpy(buf, len, src) (void)((buf) && (size_t)(len) > 0 && (strncpy((buf), (src), (len) - 1), (buf)[(len) - 1] = '\0'))

My tool reports the return value is always false. 我的工具报告返回值始终为false。 The last condition below is a kind of usual expression? 下面的最后一个条件是一种通常的表达方式吗? How can I interpret it? 我该怎么解释?

(strncpy((buf), (src), (len) - 1), (buf)[(len) - 1] = '\0'))

(strncpy((buf), (src), (len) - 1), (buf)[(len) - 1] = '\\0')) (strncpy((buf),(src),(len)-1),(buf)[(len)-1] ='\\ 0'))

Comma operator ? 逗号运算符 It's clearer now? 现在清楚了吗?

List of expressions, comma separated, the value of the expression is the one resulted by the evaluation of the last one in the list. 表达式列表,用逗号分隔,表达式的值是对列表中最后一个表达式求值的结果。

Since your last expression is an assignment with zero, of course it will always be zero. 由于您的最后一个表达式是一个零赋值,因此它始终为零。 This doesn't mean the evaluation of the whole list is useless: first term copies, last term terminates the copy with the zero char. 这并不意味着对整个列表的评估是没有用的:第一个术语的副本,最后一个术语以零个字符终止该副本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM