what is the use of #ifndefs

Bernd Petrovitsch bernd at petrovitsch.priv.at
Tue Jul 21 04:33:37 EDT 2015

Hi all!

On Die, 2015-07-21 at 11:04 +0530, Amit Pandey wrote:
[... crap deleted ...]
> Please let me know whether I was clear with the explanation.

It was clear and it is total and absolute crap:
- first, check with the .h (and .c) files in the kernel (and all others
  which get it right), that it is *not* as described above.
- second, the above approach may work (if done right) but has a some
  severe drawbacks and disadvantages:
  * you have to duplicate (lots of times!) the 3 lines ("#ifndef ...",
    "#define ...", "#endif" to all files (.c and .h) where on actually
    #includes the .h file.
  * imagine a .c file with 10 #include - you get 30 additional lines.
    And 10 is probably not the a large number for this.
  * you rely that in all places people use the very same #define macro
    for the same .h file - which is way to error-prone to use the

For non-crap solution: just look into one .h file in the kernel (or read
other answers in the thread) - no duplication etc. .....

BTW that is nothing that the Linux kernel created but everyone uses that
in the C/C++ work since ages .....

Kind regards,
"I dislike type abstraction if it has no real reason. And saving
on typing is not a good reason - if your typing speed is the main
issue when you're coding, you're doing something seriously wrong."
    - Linus Torvalds

More information about the Kernelnewbies mailing list