From: j.neuschaefer@gmx.net (Jonathan Neuschäfer)
To: kernelnewbies@lists.kernelnewbies.org
Subject: What is the adventage of macros against function
Date: Wed, 27 Apr 2011 14:25:43 +0200 [thread overview]
Message-ID: <20110427122543.GA1290@debian.debian> (raw)
In-Reply-To: <BANLkTimY7UFQy+tEoLmK-bZvU7Uc8cZQtA@mail.gmail.com>
On Wed, Apr 27, 2011 at 02:16:08PM +0530, Ramya Desai wrote:
> 2011/4/27 ?smail Baydan <ibaydan@gmail.com>:
> > Currently I am trying to learn linux kernel while looking around I saw that
> > a lot of function likes macros are defined.What is the adventage of macros
> > over functions.
> If the size of the function is very small, then the macro is better
> when compared to function. The macros are replaced at the time of
> preprocessing. However, if there is a function, then there may be
> overhead in calling the function. When there is a call, the return
> address needs to be stored on the stack. This makes some overhead. So,
> if the size of a fucction is big, then define it as function otherwise
> make it as a macro.
That's why GCC (and probably other compilers, too) has the the inline
keyword.
One important use case of macros is when the needed functionality cannot
be implemented in a function. include/linux/kernel.h offers some good
examples (e.g. ARRAY_SIZE, container_of, swap).
Hope this helps,
Jonathan Neusch?fer
next prev parent reply other threads:[~2011-04-27 12:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 8:25 What is the adventage of macros against function İsmail Baydan
2011-04-27 8:46 ` Ramya Desai
2011-04-27 9:09 ` İsmail Baydan
2011-04-27 12:25 ` Jonathan Neuschäfer [this message]
2011-04-27 14:12 ` Ozan Türkyılmaz
2011-04-27 8:57 ` Naveen Kumar
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=20110427122543.GA1290@debian.debian \
--to=j.neuschaefer@gmx.net \
--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).