* Difference between INIT_LIST_HEAD and LIST_HEAD_INIT
@ 2015-01-06 9:37 nawab
2015-01-06 15:27 ` Valdis.Kletnieks at vt.edu
2015-01-06 21:26 ` anish singh
0 siblings, 2 replies; 5+ messages in thread
From: nawab @ 2015-01-06 9:37 UTC (permalink / raw)
To: kernelnewbies
hi friends ,
i have a simple doubt when i was looking on linux/list.h
I have seen that INIT_LIST_HEAD and LIST_HEAD_INIT are performing the
same functionality,the major difference is
the argument passed.
When we have to use INIT_LIST_HEAD and LIST_HEAD_INIT??
^ permalink raw reply [flat|nested] 5+ messages in thread
* Difference between INIT_LIST_HEAD and LIST_HEAD_INIT
2015-01-06 9:37 Difference between INIT_LIST_HEAD and LIST_HEAD_INIT nawab
@ 2015-01-06 15:27 ` Valdis.Kletnieks at vt.edu
2015-01-06 16:26 ` Chen Weixiang
2015-01-06 21:26 ` anish singh
1 sibling, 1 reply; 5+ messages in thread
From: Valdis.Kletnieks at vt.edu @ 2015-01-06 15:27 UTC (permalink / raw)
To: kernelnewbies
On Tue, 06 Jan 2015 15:07:17 +0530, nawab said:
> hi friends ,
>
> i have a simple doubt when i was looking on linux/list.h
>
> I have seen that INIT_LIST_HEAD and LIST_HEAD_INIT are performing the
> same functionality,the major difference is
> the argument passed.
>
> When we have to use INIT_LIST_HEAD and LIST_HEAD_INIT??
At the risk of sounding snarky - you use INIT_LIST_HEAD when you have
an argument of the type it takes, and you use LIST_INIT_HEAD when you
have something of the type that *that* one takes. Just like math.h gives
us:
double sin(double x);
float sinf(float x);
so if you have a float, you call sinf() and if you have a double, you
call sin().
(Hint: One looks suspiciously like a data initializer, the other looks
like executable code.... :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150106/109fc439/attachment.bin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Difference between INIT_LIST_HEAD and LIST_HEAD_INIT
2015-01-06 15:27 ` Valdis.Kletnieks at vt.edu
@ 2015-01-06 16:26 ` Chen Weixiang
0 siblings, 0 replies; 5+ messages in thread
From: Chen Weixiang @ 2015-01-06 16:26 UTC (permalink / raw)
To: kernelnewbies
> >
> > When we have to use INIT_LIST_HEAD and LIST_HEAD_INIT??
>
I believe it's better to use macro LIST_HEAD(name) to define and
initialize a variable of type 'struct list_head'.
The method INIT_LIST_HEAD() is used to initialize a predefined variable
of type 'struct list_head'.
--
Best regards,
Chen Weixiang (Alex)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Difference between INIT_LIST_HEAD and LIST_HEAD_INIT
2015-01-06 9:37 Difference between INIT_LIST_HEAD and LIST_HEAD_INIT nawab
2015-01-06 15:27 ` Valdis.Kletnieks at vt.edu
@ 2015-01-06 21:26 ` anish singh
2015-01-06 22:31 ` Greg KH
1 sibling, 1 reply; 5+ messages in thread
From: anish singh @ 2015-01-06 21:26 UTC (permalink / raw)
To: kernelnewbies
On Tue, Jan 6, 2015 at 1:37 AM, nawab <nawablinux@gmail.com> wrote:
> hi friends ,
>
> i have a simple doubt when i was looking on linux/list.h
>
> I have seen that INIT_LIST_HEAD and LIST_HEAD_INIT are performing the
> same functionality,the major difference is
> the argument passed.
>
yes but that is minor difference. Major is that one is a macro and other is
a function.
> When we have to use INIT_LIST_HEAD and LIST_HEAD_INIT??
>
When do you use macro and when do you use function?
>
> _______________________________________________
> 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/20150106/d9c54d49/attachment.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Difference between INIT_LIST_HEAD and LIST_HEAD_INIT
2015-01-06 21:26 ` anish singh
@ 2015-01-06 22:31 ` Greg KH
0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2015-01-06 22:31 UTC (permalink / raw)
To: kernelnewbies
On Tue, Jan 06, 2015 at 01:26:45PM -0800, anish singh wrote:
>
>
> On Tue, Jan 6, 2015 at 1:37 AM, nawab <nawablinux@gmail.com> wrote:
>
> hi friends ,
>
> i have a simple doubt when i was looking on linux/list.h
>
> I have seen that? ?INIT_LIST_HEAD and LIST_HEAD_INIT are performing the
> same functionality,the major difference is
> the argument passed.
>
> ?
> yes but that is minor difference. Major is that one is a macro and other is
> a function.
> ?
>
> When we have to use INIT_LIST_HEAD and LIST_HEAD_INIT??
>
>
> When do you use macro and when do you use function?
It depends on your need. Look at how the two are used in the kernel, we
have thousands of examples. Seeing them should explain more than what
we can here.
Or, try it out yourself, write a tiny module using a list and see how
the different functions and macros work.
good luck,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-01-06 22:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-06 9:37 Difference between INIT_LIST_HEAD and LIST_HEAD_INIT nawab
2015-01-06 15:27 ` Valdis.Kletnieks at vt.edu
2015-01-06 16:26 ` Chen Weixiang
2015-01-06 21:26 ` anish singh
2015-01-06 22:31 ` Greg KH
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).