Below is the implementation of strlen.c as per "The Standard C Library,
size_t strlen(const char *s){
const char *sc;
for(sc = s; *sc != '\0'; ++sc)
return (sc-s); }
Is my understanding of the legality of sc = s
correct?
sc=s
is a legal assignment because since both variables are declared as const
, both protect the object that is pointed to by s. In this case, it is legal to change where sc or s both point to but any assignment (or reference?) to *s
or sc
would be illegal.