Domanda

I am finding some issue in the order the include headers are defined in the c / c++ files when i execute pclint.

Say the include order is ,

#include <sys/timerfd.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <stdarg.h>                                       
#include <string.h>

and when i execute the pclint it gives error in say , FILE is un declared etc.

Later i changed the order of include to

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <stdarg.h>                                       
#include <string.h>
#include <sys/timerfd.h>

i could see that many errors were gone . I am not able to figure out why is this behavior. I am using PC-lint for C/C++ (NT) Vers. 8.00w.

i have marked the include path as say, +libdir(D:\timesys\nitrogen6x\toolchain\include)

Thank You Brijesh

È stato utile?

Soluzione

Supposedly, the inclusion of header files does slightly matter, although it's rare to find such an occasion. Some include files use types, enums or something else that is only defined in another include file.

On Linux, for example, some functions require the inclusion of multiple headers. Some of the programs using those, fail if you include those headers in the wrong order. Kinda like the final linking stage. You have to set the libs in the correct order, otherwise you may get unresolved dependencies.

If I find an example, i will post it here.

EDIT: Found an example. Qt. Qt has the most absurdly complicated set of headers. If you include, for example, opengl.h before QtOpenGL.h, it gives you a compilation error, because inside the Qt headers it checks for the inclusion of opengl. For some reason, QtOpenGL.h must come first.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top