...
Unfortunately, const
-qualified objects cannot be used where compile-time integer constants are required, namely to define the
- size Size of a bit-field member of a structure.
- size Size of an array (except in the case of variable length arrays).
- value Value of an enumeration constant.
- value Value of a
case
constant.
If any of these are required, then an integer constant (which would be an rvalue) must be used.
...
Object-like macros do not consume memory, and, ; consequently, it is not possible to create a pointer to one. Macros do not provide for type checking because they are textually replaced by the preprocessor.
...
Code Block | ||||
---|---|---|---|---|
| ||||
#ifndef PORTNUMBER /* Might be passed on compile line */
# define PORTNUMBER 1234
#endif
#ifndef HOSTNAME /* Might be passed on compile line */
# define HOSTNAME "localhost"
#endif
/* ... */
LDAP *ld = ldap_init(HOSTNAME, PORTNUMBER);
if (ld == NULL) {
perror("ldap_init");
return(1);
}
|
...
Using numeric literals makes code more difficult to read and understand. Buffer overruns are frequently a consequence of a magic number being changed in one place (like such as in an array declaration) but not elsewhere (like such as in a loop through an array).
...