3 ms·
> It used to be said that const was a virus: once you start using it, you need to use it universally in your entire code-base. In order for const to actually w
by a1369209993 4y ago
> It used to be said that const was a virus: once you start using it, you need to use it universally in your entire code-base.
In order for const to actually work for what it's supposed to do, it does have to be viral in the direction of data flow. You should start by adding const to function arguments that point to data the function only reads (and doesn't pass the pointer to any subroutines) and expand from there. Eg:
_Bool isurl(char /*const here*/* s) {
while(isalpha(*s)) s++;
return *s == ':';
} /* s is never written through */
Then anything that passes pointers (only) to functions like isurl, and so on as is convenient.