From: bernd@petrovitsch.priv.at (Bernd Petrovitsch)
To: kernelnewbies@lists.kernelnewbies.org
Subject: what is the use of #ifndefs
Date: Tue, 21 Jul 2015 10:33:37 +0200 [thread overview]
Message-ID: <1437467622.32331.25.camel@thorin> (raw)
In-Reply-To: <CAODrRZF+y2oKqbW0TQyFzE1DnTEDQNxm0aemTwJTFFQx7oCbKg@mail.gmail.com>
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
next prev parent reply other threads:[~2015-07-21 8:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-20 10:03 what is the use of #ifndefs Ahmed Soliman
2015-07-20 15:55 ` leo kirotawa
2015-07-20 16:03 ` Stephan Müller
2015-07-20 16:11 ` Greg Freemyer
2015-07-20 17:00 ` anish singh
2015-07-21 2:24 ` Navy
2015-07-21 5:05 ` Raul Piper
2015-07-21 5:34 ` Amit Pandey
2015-07-21 7:01 ` Navy
2015-07-21 8:33 ` Bernd Petrovitsch [this message]
2015-07-21 19:44 ` Aruna Hewapathirane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437467622.32331.25.camel@thorin \
--to=bernd@petrovitsch.priv.at \
--cc=kernelnewbies@lists.kernelnewbies.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).