...
| Wiki Markup |
|---|
<ac:structured-macro ac:name="anchor" ac:schema-version="1" ac:macro-id="0a147a52f9228160-0b74af59-4d904d47-b09db5a1-3444fa822a302b7d4a4f3c62"><ac:parameter ac:name="">1</ac:parameter></ac:structured-macro> \[1\] Note that the POSIX ^®^ standard extends the set of identifiers reserved by C99 to include an open-ended set of its own. See section [2.2 Compilation Environment|http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_02] in [IEEE Std 1003.1-2008|AA. Bibliography#IEEE Std 1003.1-2008]. |
...
| Code Block | ||
|---|---|---|
| ||
#include <stddef.h>
void* my_malloc(size_t nbytes) {
void *ptr;
/* allocate storage from own pool and set ptr */
return ptr;
}
void* my_calloc(size_t nelems, size_t elsize) {
void *ptr;
/* allocate storage from own pool and set ptr */
return ptr;
}
void* my_realloc(void *ptr, size_t nbytes) {
/* reallocate storage from own pool and set ptr */
return ptr;
}
void my_free(void *ptr) {
/* return storage to own pool */
}
|
Noncompliant Code Example (errno)
| Wiki Markup |
|---|
According \[[ISO/IEC 9899-1999|AA. Bibliography#ISO/IEC 9899-1999]\], the behavior of a program is [undefined |BB. Definitions#undefined behavior] when |
a macro definition of
errnois suppressed in order to access an actual object, or the program defines an identifier with the nameerrno.
(See undefined behavior 108 of Annex J.)
The errno identifier expands to a modifiable lvalue that has type int but is not necessarily the identifier of an object. It might expand to a modifiable lvalue resulting from a function call, such as *errno(). It is unspecified whether errno is a macro or an identifier declared with external linkage. If a macro definition is suppressed to access an actual object, or a program defines an identifier with the name errno, the behavior is undefined.
Legacy code is apt to include an incorrect declaration, such as the following.
| Code Block | ||
|---|---|---|
| ||
extern int errno;
|
Compliant Solution (errno)
The correct way to declare errno is to include the header <errno.h>.
| Code Block | ||
|---|---|---|
| ||
#include <errno.h>
|
Implementations conforming to C99 are required to declare errno in <errno.h>, although some historic implementations failed to do so.
Risk Assessment
Using reserved identifiers can lead to incorrect program operation.
...
Tool | Version | Checker | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||
|
|
|
|
Related Guidelines
...