In general, no. Easy to enter silent changes.
Suppose header.h defines some macros, such as
#define WITH_FEATURE_FOO
C file including header.h validates macro
#ifdef WITH_FEATURE_FOO do_this(); #else do_that(); #endif
Your files are compiled and included with all warnings with or without header.h , but the result behaves differently. The only way to get the final answer is to analyze which identifiers the header defines / declares and sees if at least one of them appears in the pre-processed C file.
One tool that does this is Gimpel's FlexeLint. I am not paid for this, although they should :-) If you want to avoid getting around big bucks, the approach I took is to compile the C file into an object file with and without a header, if both successfully verify identical object files. If they are the same, you do not need a header (but see our include include directives, enclosed in #ifdef , which are activated by the -DWITH_FEATURE_FOO option).
source share