Rather than use TRUE, FALSE, NULL, 0 or != 0 in if/while conditions.
Additionally, corrected some example code to adhere to the recommended
coding style.
/* loop forever */
}
+## Use boolean conditions
+
+Rather than test a conditional value such as a bool against TRUE or FALSE, a
+pointer against NULL or != NULL and an int against zero or not zero in
+if/while conditions we prefer:
+
+CURLcode result = CURLE_OK;
+
+result = do_something();
+if(!result) {
+ /* something went wrong */
+ return result;
+}
+
## No assignments in conditions
To increase readability and reduce complexity of conditionals, we avoid
and instead we encourage the above version to be spelled out more clearly:
ptr = malloc(100);
- if(ptr == NULL)
+ if(!ptr)
return NULL;
## New block on a new line
#ifdef HAVE_MAGIC
void magic(int a)
{
- return a+2;
+ return a + 2;
}
#else
#define magic(x) 1