kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* What is the adventage of macros against function
@ 2011-04-27  8:25 İsmail Baydan
  2011-04-27  8:46 ` Ramya Desai
  2011-04-27  8:57 ` Naveen Kumar
  0 siblings, 2 replies; 6+ messages in thread
From: İsmail Baydan @ 2011-04-27  8:25 UTC (permalink / raw)
  To: kernelnewbies

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.
Thanks

-- 
?smail Baydan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110427/e484bd3b/attachment.html 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* What is the adventage of macros against function
  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
  2011-04-27  8:57 ` Naveen Kumar
  1 sibling, 2 replies; 6+ messages in thread
From: Ramya Desai @ 2011-04-27  8:46 UTC (permalink / raw)
  To: kernelnewbies

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.

I guess, this helps you a bit.

Regards,
Ramya.

> Thanks
>
> --
> ?smail Baydan
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* What is the adventage of macros against function
  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  8:57 ` Naveen Kumar
  1 sibling, 0 replies; 6+ messages in thread
From: Naveen Kumar @ 2011-04-27  8:57 UTC (permalink / raw)
  To: kernelnewbies

Actually you will see lot of macros defined to achieve small and modular
functionality.
this makes your code faster to execute but the binary size will be bigger.

You will see this in kernel code more because we have very low stack area
sometime may be one page(4096 bytes) of memory.
automatic variable declare and defined in function will occupy space in
stack.

In application side C expert suggest to have functions because we have very
big stack area and function adds readability
with easy debugging.

I hope this will help you in your kernel context.

Thanks,
Naveen

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.
> Thanks
>
> --
> ?smail Baydan
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110427/471ac82b/attachment.html 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* What is the adventage of macros against function
  2011-04-27  8:46 ` Ramya Desai
@ 2011-04-27  9:09   ` İsmail Baydan
  2011-04-27 12:25   ` Jonathan Neuschäfer
  1 sibling, 0 replies; 6+ messages in thread
From: İsmail Baydan @ 2011-04-27  9:09 UTC (permalink / raw)
  To: kernelnewbies

2011/4/27 Ramya Desai <ramya.desai@gmail.com>

> 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.
>
> I guess, this helps you a bit.
>
> Regards,
> Ramya.
>
> > Thanks
> >
> > --
> > ?smail Baydan
> >
> > _______________________________________________
> > Kernelnewbies mailing list
> > Kernelnewbies at kernelnewbies.org
> > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> >
>

thanks

-- 
?smail Baydan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110427/034f7707/attachment.html 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* What is the adventage of macros against function
  2011-04-27  8:46 ` Ramya Desai
  2011-04-27  9:09   ` İsmail Baydan
@ 2011-04-27 12:25   ` Jonathan Neuschäfer
  2011-04-27 14:12     ` Ozan Türkyılmaz
  1 sibling, 1 reply; 6+ messages in thread
From: Jonathan Neuschäfer @ 2011-04-27 12:25 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* What is the adventage of macros against function
  2011-04-27 12:25   ` Jonathan Neuschäfer
@ 2011-04-27 14:12     ` Ozan Türkyılmaz
  0 siblings, 0 replies; 6+ messages in thread
From: Ozan Türkyılmaz @ 2011-04-27 14:12 UTC (permalink / raw)
  To: kernelnewbies

On Wed, 27 Apr 2011, Jonathan Neusch?fer wrote:
> That's why GCC (and probably other compilers, too) has the the inline
> keyword.

inline keyword is  widely supported by c compilers. Modern compiles even 
now support optimizations based on automatic inline to speed up programs 
etc. (OPTIMIZE_INLINING=y. It uses several flags to use that 
optimization).

-- 
Ozan, BSc, BEng

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-04-27 14:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2011-04-27 14:12     ` Ozan Türkyılmaz
2011-04-27  8:57 ` Naveen Kumar

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).