...
Wiki Markup |
---|
In this noncompliant code example \[[GCC Bugs|http://gcc.gnu.org/bugs.html#nonbugs_c]\], the author uses preprocessor directives to specify platform-specific arguments to {{memcpy()}}. However, if {{memcpy()}} is implemented using a macro, the code will result in undefined behavior. For example, this code will compile using GCC version 3.3 and later, but will not compile using GCC versions prior to 3.3 if {{memcpy()}} is a macro. |
Code Block | ||
---|---|---|
| ||
memcpy(dest, src, #ifdef PLATFORM1 12 #else 24 #endif ); |
Compliant Code Example
Wiki Markup |
---|
In this compliant solution \[[GCC Bugs|http://gcc.gnu.org/bugs.html#nonbugs_c]\], the appropriate call to {{memcpy()}} is determined outside the function call. |
Code Block | ||
---|---|---|
| ||
#ifdef PLATFORM1 memcpy(dest, src, 12); #else memcpy(dest, src, 24); #endif |
...