2

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

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
user2190483
  • 269
  • 1
  • 5
  • 22
  • Does it compoile in both cases? – Devolus Dec 09 '13 at 13:16
  • Strange behavior, did you change change some Macro in headers file ? Or redefined some without using `#IFNDEF` – Gabson Dec 09 '13 at 13:29
  • 2
    Wow, that source file must be quite a hodgepodge. – Pete Becker Dec 09 '13 at 13:36
  • Looks like `sys/timerfd.h` is depending on `stdio.h` but fails to `#include` it if it hasn't already been included. Did `sys/timerfd.h` come with the compiler? – Klas Lindbäck Dec 09 '13 at 13:40
  • it compiles and works fine . The problem is only with pclint – user2190483 Dec 09 '13 at 14:21
  • 1
    If you got error like this /usr/include/x86_64-linux-gnu/sys/timerfd.h:46:28: error: unknown type name ‘clockid_t’ it is a known "issue" that arises when you compile with "-std=c99". When compiling without -std=anything, features.h falls back to a recent version of POSIX which provides clockid_t in time.h, otherways a way to hide the problem is to include sys/types.h before sys/timerfd.h in your code. I think this is what you have done putting the include at the bottom. Issue tracked here: http://comments.gmane.org/gmane.linux.debian.devel.bugs.general/867712 – Jekyll Dec 09 '13 at 16:58

1 Answers1

1

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.

Joao Pincho
  • 939
  • 2
  • 11
  • 26