开发者

strcmp and wcscmp

开发者 https://www.devze.com 2023-01-08 14:26 出处:网络
Is this if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &a开发者_StackOverflowmp;&

Is this

if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &a开发者_StackOverflowmp;&
    (wcscmp(FileData.cFileName, L".") != 0) &&
    (wcscmp(FileData.cFileName, L"..") != 0) )

the same as this:

if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
    wcscmp(FileData.cFileName, L".") &&
    wcscmp(FileData.cFileName, L"..") )

And also if you use strcmp instead of wcscmp? It should check equality (strict) of the name with ".." and "." (directory search).

Thanks!


If I'm not mistaken, both examples do the same thing.


In C, "true" is defined as "not zero". "false" is defined as "zero". So yes, they're the same.

Do be careful about methods that return non-primitive types, though; in C++, operator overloading could make "!= 0" not actually compare something with zero :-P. Not a problem here, though.

Also, if you don't put in the parentheses, make sure you understand the order of operations.

0

精彩评论

暂无评论...
验证码 换一张
取 消