From mboxrd@z Thu Jan 1 00:00:00 1970 From: bernd@petrovitsch.priv.at (Bernd Petrovitsch) Date: Tue, 21 Jul 2015 10:33:37 +0200 Subject: what is the use of #ifndefs In-Reply-To: References: Message-ID: <1437467622.32331.25.camel@thorin> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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 pattern. 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, Bernd -- "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