All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: jengelh@medozas.de, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 6/6] netfilter: xtables: add const qualifiers
Date: Thu, 11 Feb 2010 10:56:59 +0100	[thread overview]
Message-ID: <4B73D46B.8090701@trash.net> (raw)
In-Reply-To: <b6fcc0a1002110142p524de4ddm5260751cc68f4482@mail.gmail.com>

Alexey Dobriyan wrote:
> On Thu, Feb 11, 2010 at 11:27 AM, Patrick McHardy <kaber@trash.net> wrote:
>> Alexey Dobriyan wrote:
>>>> -static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
>>>> -   const struct net_device *in, const struct net_device *out)
>>>> +static inline int
>>>> +ebt_basic_match(const struct ebt_entry *e, const struct ethhdr *h,
>>>> +                const struct net_device *in, const struct net_device *out)
>>> These const modifiers are pointless because compilers are smart enough
>>> to notice non-modifiability and generate the very same code in both cases.
>>>
>>> Nowadays, half of functions declarations in generic
>>> xtables/iptables/ip6tables/arptables
>>> code are littered with const which makes them pretty unpleasant to read.
>> Well, the benefit is that the compiler can catch accidental modification
>> of data that is supposed to be constant.
> 
> Did it ever? Realistically?

Yes, occasionally it has caught typos or other variable mixups for me.
It also documents that a variable is only supposed to be read.

>>From what I see, const is used with string functions
> (to make string literals go to rodata) and with structures full of hooks
> (to make them go to rodata).

Yes, that's also a reason.

>>>> -    struct ebt_entry *e = (struct ebt_entry *)chain->data;
>>>> +    const struct ebt_entry *e = (struct ebt_entry *)chain->data;
>>> And such things are wrong (not second const).
>> What's wrong about this?
> 
> Should it be (const struct ebt_entry *)?

That's not necessary. Its just declaring the the memory should
not be modified through e. The const qualification happens
automatically.

  reply	other threads:[~2010-02-11  9:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-11  9:14 [PATCH 6/6] netfilter: xtables: add const qualifiers Alexey Dobriyan
2010-02-11  9:27 ` Patrick McHardy
2010-02-11  9:42   ` Alexey Dobriyan
2010-02-11  9:56     ` Patrick McHardy [this message]
2010-02-11 13:12       ` Jan Engelhardt
  -- strict thread matches above, loose matches on Subject: below --
2010-02-10 17:39 Code cleanups Jan Engelhardt
2010-02-10 17:39 ` [PATCH 6/6] netfilter: xtables: add const qualifiers Jan Engelhardt
2010-02-11  9:00   ` Patrick McHardy
2010-02-11 13:27     ` Jan Engelhardt
2010-02-11 16:06       ` Patrick McHardy
2010-02-11 16:22         ` Jan Engelhardt
2010-02-11 16:27           ` Patrick McHardy
2010-02-11 17:04             ` Jan Engelhardt
2009-11-03 18:04 Xtables cleanup patches Jan Engelhardt
2009-11-03 18:04 ` [PATCH 6/6] netfilter: xtables: add const qualifiers Jan Engelhardt

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=4B73D46B.8090701@trash.net \
    --to=kaber@trash.net \
    --cc=adobriyan@gmail.com \
    --cc=jengelh@medozas.de \
    --cc=netfilter-devel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.