迭代 char** 为什么这有效?
我拿起这段代码,将其复制到我的程序中。这对我来说似乎是一种迭代 char** 的新方法:
char** vArray; // The array containing values
// Go throught properties
if(szKey == "KeyMgmt")
{
vArray = (char**)g_value_get_boxed((GValue*)value);
for( ; vArray && *vArray ; vArray++) // Why does this work ?!
pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
// ...
}
它看起来像一个魅力,但我不明白为什么! vArray 应该包含一个地址,对吧? *vArray 是“字符串”值。那么,为什么当我将一个地址与其值“与”时,这会给我一个相等性呢?
I picked up a this piece of code I copy past to my program. This seems to be a new way to me to iterate through char**:
char** vArray; // The array containing values
// Go throught properties
if(szKey == "KeyMgmt")
{
vArray = (char**)g_value_get_boxed((GValue*)value);
for( ; vArray && *vArray ; vArray++) // Why does this work ?!
pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
// ...
}
It looks like to work like a charm but I don't understant why! vArray is Supposed to contain an adress right? And *vArray the "string" value. So why when I "AND" an address with its value this give me an equality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
vArray && *vArray
相当于(vArray != NULL) && (*vArray != NULL)
首先检查指针
vArray
是否不是NULL
,并且假设它不是NULL
,检查它指向的指针是否不是NULL
。vArray && *vArray
is equivalent to(vArray != NULL) && (*vArray != NULL)
It's first checking that the pointer
vArray
isn'tNULL
and, assuming it is notNULL
, checking that the pointer it points to isn'tNULL
.循环条件是
这基本上是简写
,如果
char**
指针非空并且指向非空的char*
,则循环条件为 true。The loop condition is
This is basically shorthand for
which is true if the
char**
pointer is non-null and points to achar*
which is non-null.