Dead functions and /*NOTREACHED*/
karl at haddock
karl at haddock
Thu Sep 4 05:21:00 AEST 1986
epimass!jbuck (Joe Buck) writes:
>In article <86900019 at haddock> karl at haddock (The Walking Lint) writes:
>>[discussion of some problems with adding "dead functions" to C]
>>But I really hate having to write /*NOTREACHED*/ to keep lint happy!
>
>There's a fix for this that doesn't do violence to the language.
>There should be another "special comment" lint recognizes that's
>present in the lint library (/*DEADEND*/ or something). Then
>functions like "exit" are marked once in the lint library, and
>user-written functions that always call exit would also be understood
>to be "dead". Voila! lint now understands about exit, and is able
>to find unreachable code that it currently may miss.
(I don't think adding a new type is "violence to the language", but...)
Not bad; it doesn't help with the compiler's optimization, but it would take
care of the /*NOTREACHED*/ problem. And the user can use /*DEADEND*/ on his
own functions even if lint isn't smart enough to propagate dead-knowledge.
(If it is, then the magic comment may not even be necessary; the line
void exit(int) { for (;;); }
int the lint library should suffice.)
>While I'm at it, a similar comment could be added to tell lint that
>a function like malloc or calloc always returns an aligned pointer.
Perhaps.
>I understand that ANSI C has a different solution for this,
No. "void *" has nothing to do with guaranteed alignment, it just means
"pointer to unknown".
Karl W. Z. Heuer (ima!haddock!karl; karl at haddock.isc.com), The Walking Lint
More information about the Comp.lang.c
mailing list