I'm having trouble with the above code. The standard says that invalid will only be updated if it is not NULL (7.22.1.4(5) and 7.22.1.4(7)).Code:void validate(int *arg, const char *optarg, ...) { errno = 0; char **invalid = NULL; *arg = (int) strtol(optarg, invalid, 10);
However I can't seem to be able to define a working pointer to optarg:
const char **invalid = &optarg -> fails on the strtol call. invalid is expected to be a char **.
char **invalid = &optarg -> is obviously wrong.
The alternative is to drop the const qualifier from the validate function definition. But I'd rather it stayed. How can I solve this?