...
EXP05-EX1: An exception to this rule is allowed when it is necessary to cast away const when invoking a legacy API that does not accept a const argument, provided the function does not attempt to modify the referenced variable. For example, the following code casts away the const qualification of INVFNAME in the call to the audit_log() function.
| Code Block |
|---|
void audit_log(char *errstr) { /* Legacy function defined elsewhere - cannot be modified */ void audit_log(char *errstr) { fprintf(stderr, "Error: %s.\n", errstr); } /* ... */ char const INVFNAME[] = "Invalid file name."; audit_log((char *)INVFNAME); /* ... */ |
...