Here is how strtol
has to be declared according to § 7.22.1.4
from C11 (n1570):
#include <stdlib.h>
long int strtol (const char *restrict nptr,
char **restrict endptr,
int base);
As far as I know, the restrict
keyword means that the object referenced by the lvalue *nptr
will be accessed only with it or a value directly derived from it.
However, a lot of programmers, and even experienced ones, use strtol
in the following way:
#include <stdlib.h>
strtol (p, &p, 10);
In that case, **endptr == **&p == *p == *nptr
, and the behavior is undefined. Is it right?
No. Nothing is accessed via **endptr
in strtol
. Only *endptr
, a completely separate object, is accessed.