C
CBFalconer
Richard said:CBFalconer said:
What is the basis for your belief?
I think I remember reading it in the C standard.
Richard said:CBFalconer said:
What is the basis for your belief?
CBFalconer said:I think I remember reading it in the C standard.
Harald said:CBFalconer wrote:
... snip ...
No, C_guy wants to know what he can delete. [snip]
Fine, then given
/* Begin file: */
#include <stdio.h>
int main()
{
puts("Hello, World");
return 0;
}
/* End of file */
are you saying C_guy wants the inclusion of <stdio.h> to go?
No, he wants to know if it CAN BE removed.
Does anyone know of a (hopefully free) tool that can traverse a
project and determine which "#include"s are not needed or needed in
every .C file? This would be helpful in removing header inclusions
that are redundant and/or unnecessary.
Thanks!
John said:AFAIK none exists, because it's an absolute bitch of a problem in the
general case.
Harald said:CBFalconer said:Harald said:CBFalconer wrote:
... snip ...
No, C_guy wants to know what he can delete. [snip]
Fine, then given
/* Begin file: */
#include <stdio.h>
int main() {
puts("Hello, World");
return 0;
}
/* End of file */
are you saying C_guy wants the inclusion of <stdio.h> to go?
No, he wants to know if it CAN BE removed.
You managed to avoid the actual question.
/* Begin file: */
#include <stdio.h>
#include <stdlib.h>
int main() {
puts("Hello, World");
return 0;
}
/* End of file */
Do you believe C_guy wants to have the same information for both
headers? I would imagine he wants to know that <stdlib.h> can be
removed, and that <stdio.h> should stay, even though it could be
removed as well.
If you start with none, the compiler will tell every time it
encounters something that would have been in a header. Add one at a
time till the diagnostics disappear.
Other than a pretty small time penalty, including an unnecessary
header or two usually doesn't cause problems.
Richard Heathfield said:
Oops. Two negatives make a positive, don't they? - and I'm *positive* that
I can't find no reference to this claimed prohibition.
Anyway - chapter & verse would be nice.
No, stdio.h can't be omitted. Some compiler systems may not object, butHarald said:/* Begin file: */
#include <stdio.h>
#include <stdlib.h>
int main() {
puts("Hello, World");
return 0;
}
/* End of file */
[snip]
any C99 system should. If the compiler is sufficiently poor it won't
give any worthwhile information.
Ron said:With gcc, I had to add the -Wall flag to get it to tell me that I had
left a library unincluded.
jacob said:The lcc-win compiler will output all files included
in a given source file using the
lcc -M
I think I remember reading it in the C standard.
What does the standard say about vfprintf()? I believe the standard (or
at least one of the free drafts of the standard) says to include both
<stdarg.h> and <stdio.h> (7.19.6.8)
Richard Heathfield said:
Oops. Two negatives make a positive, don't they? - and I'm *positive* that
I can't find no reference to this claimed prohibition.
Anyway - chapter & verse would be nice.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999- Hide quoted text -
- Show quoted text -
Richard Heathfield said:
Oops. Two negatives make a positive, don't they? - and I'm *positive* that
I can't find no reference to this claimed prohibition.
Anyway - chapter & verse would be nice.
Richard Heathfield said:Nick Keighley said:
Richard Heathfield said:
CBFalconer said:
Richard Heathfield wrote:
CBFalconer said:
Ben Bacarisse wrote:That does not work if a pair (or more) of include files need each
other but are (together) not needed by the rest of the code. This
is poor design, but a robust method should be able to
detect it.
I believe this is not allowed with standard C system headers.
What is the basis for your belief?
I think I remember reading it in the C standard.
I can't find no reference to this claimed prohibition.
Oops. Two negatives make a positive, don't they? - and I'm *positive*
that I can't find no reference to this claimed prohibition.
Anyway - chapter & verse would be nice.
I *think* this bit
***
AMERICAN NATIONAL STANDARD X3.159-1989
para 4.1.2
Standard Headers
[...]
line 29
Headers may be included in any order; each may be included
more than once in a given scope, with no effect different from
being included only once,
[except <assert.h> is funny]
***
So I don't see how one header can be dependent on another.
I see no reason why the above paragraph precludes <stddef.h> from being
included by, say, <stdio.h> and <stdio.h> by <stddef.h>.
Then how comes lint does it?
Nick Keighley said:
I *think* this bit***
AMERICAN NATIONAL STANDARD X3.159-1989para 4.1.2
Standard Headers
[...]
line 29
Headers may be included in any order; each may be included
more than once in a given scope, with no effect different from
being included only once,
[except <assert.h> is funny]
***So I don't see how one header can be dependent on another.
I see no reason why the above paragraph precludes <stddef.h> from being
included by, say, <stdio.h> and <stdio.h> by <stddef.h>.
Committee Response
No Standard library header includes another Standard library header.
The header <math.h> does not define INT_MIN or INT_MAX. A program that
wants to check the return value for equality with one of these macros must
include <limits.h>.
(e-mail address removed) said:
I see no reason why [4.1.2 line 29] precludes <stddef.h> from being
included by, say, <stdio.h> and <stdio.h> by <stddef.h>.I think that makes it pretty clear that a std header can't include
another.
In my /usr/include, I have <stddef.h> included by <locale.h>, <stdio.h>,
<stdlib.h>, <string.h>, and <time.h>. I have checked one of these headers
(<string.h>, as it happens) to see if its inclusion is conditional on
being invoked in non-conforming mode, and it doesn't appear to be.
So either you're wrong - which is possible - and the Committee is wrong -
which is unlikely, or the "as if" rule applies - which is probable, and in
which case a standard library header /can/ include another standard
library header, as long as it doesn't look like it - or the implementation
is non-C90-conforming - which is unlikely.
No Standard library header [is required to include] another Standard library header.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.