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?
vArray && *vArray
is equivalent to (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
.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.