Closed XRevan86 closed 6 years ago
I might do some changes so that it fits more with my codestyle, though.
If you mean g_strcmp0 () != 0
, then it is recommended to have an explicit "0" there, because it is not a logical expression. After all, 0 (FALSE) is success for strcmp(), it's more like an exit code.
The C language uses the value 0 for many purposes. As a numeric value, the end of a string, a null pointer and the
FALSE
boolean. To make the code clearer, you should write code that highlights the specific way 0 is used. So when reading a comparison, it is possible to know the variable type. For boolean variables, an implicit comparison is appropriate because it’s already a logical expression. Other variable types are not logical expressions by themselves, so an explicit comparison is better.
or use purple_strequal()
(which is just a wrapper for g_strcmp0()
) as it's slightly clearer about what's going on?
gboolean
purple_strequal(const gchar *left, const gchar *right)
{
return (g_strcmp0(left, right) == 0);
}
Interesting choice, Pidgin :-).
It used to be a lot more of a complicated function, before g_strcmp0()
existed :)
@EionRobb, ah, now it makes more historical sense :-).
Thanks, shot myself in the foot there. I should stop setting the stanza to
null
in lurch. I might do some changes so that it fits more with my codestyle, though.