#ifndef MACROS_NULLCHECK_H_ #define MACROS_NULLCHECK_H_ #include <assert.h> #define NULLCHECK(x) assert(x != (void *) 0); #endif
If I used this style as a template for declaring macros, what conditions would you have?
puts brackets around the argument (it prevents problems when passing expressions)
do not put it; at the end (use will be more natural)
#define NULLCHECK (x) assert ((x)! = (void *) 0)
One change I could make is to comment on the closure #endif:
#endif
#endif // MACROS_NULLCHECK_H_
This makes it easier to understand what this one does #endifwhen the file is larger than the screen.
, , ..
assert((x) != (void*) 0)
, , ( ), , .
, ,
NULLCHECK(pSomething);
C- .
- CERT C Secure Wiki:
PRE00-.PRE01-.PRE02-. PRE03-. typedefsPRE10-. do-whilePRE11-.PRE31-. , , , ,PRE32-.
. , .
To enforce ;, use
;
#define NULLCHECK(x) do { assert((X)); } while (0)
Source: https://habr.com/ru/post/1717336/More articles:Set working directory in javascript - javascriptHow bad is opening and closing a SQL connection several times? What is the exact effect? - sql-serverWhy can I "collapse" the range of integers by half the size without losing information? - mathmsxml3.dll: loading of the specified resource failed - when using XMLHTTP - xmlhttprequestProblem with Awk & Grep - linuxIs table good practice the best way to make headings in a table? - htmllarge versus nested static machines - cIE8 error with CSS - cssWeb Parts and Downloads? - downloadHow can I make img and text link as a link to the same place, and both become active when it hangs, regardless of which one Iām soaring to? - cssAll Articles