* using sizeof operator
@ 2012-01-22 18:14 Sukrit Sangwan
2012-01-22 18:27 ` Daniel Baluta
2012-01-22 18:28 ` Sukrit Sangwan
0 siblings, 2 replies; 6+ messages in thread
From: Sukrit Sangwan @ 2012-01-22 18:14 UTC (permalink / raw)
To: kernelnewbies
There are instances in the code where sizeof(*ptr) is used. e.g.
in net/802/garp.c
const struct garp_msg_hdr *gm;
if (!pskb_may_pull(skb, sizeof(*gm)))
return -1;
i want to ask is there any sense in using sizeof(struct garp_msg_hdr)
instead of sizeof(*gm) in the above example.
Thanks
--
Sukrit Sangwan
IIT Roorkee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120122/2d767a90/attachment.html
^ permalink raw reply [flat|nested] 6+ messages in thread* using sizeof operator 2012-01-22 18:14 using sizeof operator Sukrit Sangwan @ 2012-01-22 18:27 ` Daniel Baluta [not found] ` <CAF5YyJMJN7ZZMuP-K7Bp2W7dVHd8sGeoeK_+1A2ho+FtWD2Fww@mail.gmail.com> 2012-01-22 18:28 ` Sukrit Sangwan 1 sibling, 1 reply; 6+ messages in thread From: Daniel Baluta @ 2012-01-22 18:27 UTC (permalink / raw) To: kernelnewbies On Sun, Jan 22, 2012 at 8:14 PM, Sukrit Sangwan <sukritsangwan@gmail.com> wrote: > There are instances in the code where sizeof(*ptr) is used. e.g. > in net/802/garp.c > ? ? ? ? ? const struct garp_msg_hdr *gm; > ? ? ? ? ? if (!pskb_may_pull(skb, sizeof(*gm))) > ?return -1; > i want to ask is there any sense in using sizeof(struct garp_msg_hdr) > instead of sizeof(*gm) in the above example. Imagine what would happen if you change the name of struct garp_msg_hdr; thanks, Daniel. ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <CAF5YyJMJN7ZZMuP-K7Bp2W7dVHd8sGeoeK_+1A2ho+FtWD2Fww@mail.gmail.com>]
* using sizeof operator [not found] ` <CAF5YyJMJN7ZZMuP-K7Bp2W7dVHd8sGeoeK_+1A2ho+FtWD2Fww@mail.gmail.com> @ 2012-01-22 20:21 ` Daniel Baluta 0 siblings, 0 replies; 6+ messages in thread From: Daniel Baluta @ 2012-01-22 20:21 UTC (permalink / raw) To: kernelnewbies On Sun, Jan 22, 2012 at 10:17 PM, Sukrit Sangwan <sukritsangwan@gmail.com> wrote: > I found an instance where sizeof(struct xyz) is used instead of > sizeof(variablename). > I want to ask if it would be appropriate to contact the author about the > same. Well, this doesn't really matter, but the recommended practice is to use sizeof(*pointer); Please keep intact Cc's list. thanks, Daniel. ^ permalink raw reply [flat|nested] 6+ messages in thread
* using sizeof operator 2012-01-22 18:14 using sizeof operator Sukrit Sangwan 2012-01-22 18:27 ` Daniel Baluta @ 2012-01-22 18:28 ` Sukrit Sangwan 2012-01-22 19:09 ` Jonathan Neuschäfer 2012-01-23 10:42 ` Bernd Petrovitsch 1 sibling, 2 replies; 6+ messages in thread From: Sukrit Sangwan @ 2012-01-22 18:28 UTC (permalink / raw) To: kernelnewbies also i want to ask why not use simply 8 instead of sizeof(u8). -- Sukrit Sangwan IIT Roorkee -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120122/2dd6e494/attachment.html ^ permalink raw reply [flat|nested] 6+ messages in thread
* using sizeof operator 2012-01-22 18:28 ` Sukrit Sangwan @ 2012-01-22 19:09 ` Jonathan Neuschäfer 2012-01-23 10:42 ` Bernd Petrovitsch 1 sibling, 0 replies; 6+ messages in thread From: Jonathan Neuschäfer @ 2012-01-22 19:09 UTC (permalink / raw) To: kernelnewbies On Sun, Jan 22, 2012 at 11:58:30PM +0530, Sukrit Sangwan wrote: > also i want to ask why not use simply 8 instead of sizeof(u8). That would be 1 most of the time. sizeof returns the size in bytes (according to the C reference manual in K&R's book). Apart from that, sizeof(u8) is more explicit about the intention. HTH, Jonathan Neusch?fer ^ permalink raw reply [flat|nested] 6+ messages in thread
* using sizeof operator 2012-01-22 18:28 ` Sukrit Sangwan 2012-01-22 19:09 ` Jonathan Neuschäfer @ 2012-01-23 10:42 ` Bernd Petrovitsch 1 sibling, 0 replies; 6+ messages in thread From: Bernd Petrovitsch @ 2012-01-23 10:42 UTC (permalink / raw) To: kernelnewbies On Son, 2012-01-22 at 23:58 +0530, Sukrit Sangwan wrote: > also i want to ask why not use simply 8 instead of sizeof(u8). Because it is wrong. Bernd -- Bernd Petrovitsch Email : bernd at petrovitsch.priv.at LUGA : http://www.luga.at ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-01-23 10:42 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-22 18:14 using sizeof operator Sukrit Sangwan
2012-01-22 18:27 ` Daniel Baluta
[not found] ` <CAF5YyJMJN7ZZMuP-K7Bp2W7dVHd8sGeoeK_+1A2ho+FtWD2Fww@mail.gmail.com>
2012-01-22 20:21 ` Daniel Baluta
2012-01-22 18:28 ` Sukrit Sangwan
2012-01-22 19:09 ` Jonathan Neuschäfer
2012-01-23 10:42 ` Bernd Petrovitsch
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).