2

What is the purpose of defining _LINUX_EXPORT_H in include/linux/export.h? It seems to be defined in this file and never referenced anywhere else. Is it redundant?

Link: _LINUX_EXPORT_H in torvalds/linux on github

  • 5
    Are you asking about the purpose of include guards? – steeldriver Mar 3 at 1:39
  • 1
    It appears that the questioner is asking for the purpose of that macro not knowing that it is an include guard. – JdeBP Mar 3 at 7:04
2

If you look carefully at the file, it starts and ends with these lines:

#ifndef _LINUX_EXPORT_H
#define _LINUX_EXPORT_H
...
#endif /* _LINUX_EXPORT_H */

These lines mean that if the file is included twice (either through a mistake or through including another file that includes this file) then the second time around the value is defined, and so the whole file is effectively skipped.

These are commonly known as "header guards" or "include guards" and you'll note that many of the standard include files use this pattern; e.g pwd.h has

#ifndef _PWD_H
#define _PWD_H  1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.