CBFalconer said:
You can't undef everything. For example, a prototype. You can do
an xref of both the files and see if there is anything in common.
This answer assumes that xyz.h has a form that is not indicated by the
question.
You can #undef everything in xyz.h if everything in xyz.h is #undefable
(tautology) - it is not mandatory that xyz.h contains something that in not
#undefable - my question was a conditional (if) on all the definitions in
xyz.h being #undefed - so xyz.h must be in that class of headers in which
all the definitions can be #undefed - there exist many headers that satisfy
that condition.
Strictly, (as you obviously know from your fine erudition in this forum)
prototypes are declarations not definitions. My question was about
definitions - I was rather vaguely assuming thet foo.c didn't refer to any
functions prototyped in in xyz.h - I thought the behaviour of PC-Lint wrt
referring to functions prototyped in the header had already been
established - I was wanting to extend that knowledge to understanding how
PC-Lint dealt with #undef in this particular case (I do want to know more
generally as well, but since you thought this was too broad a question to
ask, I just asked a specific question - hoping it might give me some
indication of what PC-Lint is able to do with code that has #undefs)
So here is my question again, but refined for what I thought was the
already-understood behaviour of PC-Lint wrt to prototypes:
If all (the all here is all-important) the definitions in xyz.h were
#undef-ed in foo.c (where xyz.h is included)
-- the new bit ------
and foo.c does not refer to any function prototyped in in xyz.h
----------------------
then will PC-Lint be able to
detect that xyz.h need not be included in foo.c?
The Jesuits would still see three flaws in my question and, since it might
amuse the readers of this forum, and I'm feeling Jesuitical, I'll tell you
two (-;
1. PC-Lint might be able to "detect" (your sloppy usage eejit Connolly) the
header need not be included - surely the point is what PC-Lint "reports" -
it might know, but not tell you.
2. The wording "need not be included" (your sloppy usage eejit Connolly) is
problematic for many - take as an example (just an example - there are many
more cases) abc.c with header abc.h that declares only the prototypes of
functions in abc.c, where the functions in abc.c are decalared in an order
such that no function refers to any function later in the text of the file
abc.c, and the declarations in abc.h agree with the definitions in abc.c,
then abc.h "need not be included" in abc.c - but many would argue that the
inclusion of abc.h in abc.c is "desirable", to keep the declarations
consistent with the definitions, in case the definition of the function
changes in the future.
3. An exercise for the reader.