简体   繁体   English

迭代char **为什么会起作用?

[英]iterate char** why does this work?

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 **的一种新方法:

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? vArray应该包含地址吗? And *vArray the "string" value. 和* vArray的“字符串”值。 So why when I "AND" an address with its value this give me an equality? 那么,为什么当我用其值“和”一个地址时却能给我带来平等的机会?

vArray && *vArray is equivalent to (vArray != NULL) && (*vArray != NULL) vArray && *vArray等效于(vArray != NULL) && (*vArray != NULL)

It's first checking that the pointer vArray isn't NULL and, assuming it is not NULL , checking that the pointer it points to isn't NULL . 首先检查指针vArray不为NULL ,并假设其不为NULL ,然后检查其指向的指针是否为NULL

The loop condition is 循环条件是

vArray && *vArray

This is basically shorthand for 这基本上是

(vArray != 0) && (*vArray != 0)

which is true if the char** pointer is non-null and points to a char* which is non-null. 如果char**指针为非null并指向非null的char* ,则为true。

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

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