User Tools

Site Tools


sei_cert_c_coding_standard

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
sei_cert_c_coding_standard [2019/08/06 21:04]
rpjday [2.2 PRE31-C. Avoid side effects in arguments to unsafe macros]
sei_cert_c_coding_standard [2019/08/06 21:05]
rpjday [2.3 PRE32-C. Do not use preprocessor directives in invocations of function-like macros]
Line 23: Line 23:
 </​code>​ </​code>​
 ==== 2.3 PRE32-C. Do not use preprocessor directives in invocations of function-like macros ==== ==== 2.3 PRE32-C. Do not use preprocessor directives in invocations of function-like macros ====
 +
 +The arguments to a macro must not include preprocessor directives, such as #define, #ifdef, and #include.
 +
 +<​code>​
 +void func(const char *src) {
 +  /* Validate the source string; calculate size */
 +  char *dest;
 +  /* malloc() destination string */
 +  memcpy(dest,​ src,
 +    #ifdef PLATFORM1
 +      12
 +    #else
 +      24
 +    #endif
 +  );
 +  /* ... */
 +}
 +</​code>​
  
 ===== 3 Declarations and Initialization (DCL) ===== ===== 3 Declarations and Initialization (DCL) =====
sei_cert_c_coding_standard.txt ยท Last modified: 2019/08/06 21:17 by rpjday