Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1185031
| From | Andrew Morton <akpm@linux-foundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code |
| Date | 2015-07-15 22:40 +0200 |
| Message-ID | <pMBDc-1Vd-11@gated-at.bofh.it> (permalink) |
| References | <pM2m6-7iE-5@gated-at.bofh.it> <pM2m7-7iE-39@gated-at.bofh.it> <pMj3z-8mY-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, 15 Jul 2015 07:22:32 +0930 Rusty Russell <rusty@rustcorp.com.au> wrote: > Minfei Huang <mhuang@redhat.com> writes: > > From: Minfei Huang <mnfhuang@gmail.com> > > > > It is not elegance, if we use function directly as the argument, like > > following: > > > > bool each_symbol_section(bool (*fn)(const struct symsearch *arr, > > struct module *owner, > > void *data), void *data); > > > > Here introduce a type defined function find_symbol_in_section_t. Now > > we can use these type defined function directly, if we want to pass > > the function as the argument. > > > > bool each_symbol_section(find_symbol_in_section_t fn, void *data); > > I disagree. > > It's shorter, but it's less clear. typedefs on functions are not very > useful: > 1) They require readers to look in two places to see how to use the > function (ie each_symbol_section). > 2) They can't use the typedef to declare their function, since that > doesn't work in C. > > If the function were being used many times, it makes sense. But > it's only used twice, once static inside module.c. > Using a foo_t typedef for a function callback is a common pattern. It's (almost) the only approved use of typedefs. The usage is widespread enough that when one sees a foo_t type, one says "ahah, that's a function pointer". Sorry, but I don't think "Rusty doesn't like it" is a good reason for the module code to be different. All of us dislike some aspects of kernel coding practices, but we go along because consistency is more important. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Rusty Russell <rusty@rustcorp.com.au> - 2015-07-15 02:50 +0200
Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Minfei Huang <mhuang@redhat.com> - 2015-07-15 04:10 +0200
Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Andrew Morton <akpm@linux-foundation.org> - 2015-07-15 22:40 +0200
Re: [PATCH 1/2] Define find_symbol_in_section_t as function type to simplify the code Rusty Russell <rusty@rustcorp.com.au> - 2015-07-16 13:40 +0200
csiph-web