[neomutt-devel] Uniformize structures storing operations

Pietro Cerutti gahr at gahr.ch
Wed Feb 15 18:18:13 CET 2017


On 2017-Feb-15, 12:12, Damien Riegel wrote:
> On Wed, Feb 15, 2017 at 04:56:14PM +0000, Pietro Cerutti wrote:
> > On 2017-Feb-15, 11:41, Damien Riegel wrote:
> > > 2. Typedef'ing function pointers
> > > 
> > > I agree that it improves readability when a function pointer is passed
> > > as an argument to another function. Example from Stack Overflow [2]:
> > > 
> > >   extern void (*signal(int, void(*)(int)))(int);
> > > vs.
> > >   typedef void (*SignalHandler)(int signum);
> > >   extern  SignalHandler signal(int signum, SignalHandler handler);
> > > 
> > > But for `ops` stored in a structure like in the three examples above it
> > > doesn't make much difference, it only adds one level of indirection
> > > when reading the code. Moreover in the coding style discussion, it seems
> > > we generally want to avoid typedefs (except in a few cases). So does it
> > > also apply here?
> > 
> > Speaking for hcache, I decided to typedef the types of the functions
> > used as operations in order to provide proper documentation for them.
> > So, for function pointers typedefs are fine to me.
> 
> I don't get it, there doesn't seem to be a limitation here. If I take
> FFmpeg as exemple, it seems perfectly fine to embed this comment within
> the struct definition:
> 
> Code:
> https://github.com/FFmpeg/FFmpeg/blob/master/libavcodec/avcodec.h#L3716-L3727
> Doc:
> https://ffmpeg.org/doxygen/3.0/structAVCodec.html#a77d3f51b26f7e32894d5d3adf28cd0d7

Sure, I just thought it was nicer to have them top-level, and the actual
struct hidden at the bottom of the file ;) The fact that I also provided
the HCACHE_BACKEND_OPS macro means that people implementing backends do
not necessariliy need to know about the struct used to store the
operations (of course the compiler still needs to know it, in my current
implementation).

Anyway, if there's consensus about not using typedefs for function
pointers and having the documentation inline in the struct holding them,
I won't object :)

-- 
Pietro Cerutti
gahr at gahr.ch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1020 bytes
Desc: not available
URL: <http://mailman.neomutt.org/pipermail/neomutt-devel-neomutt.org/attachments/20170215/89faf6a7/attachment.sig>


More information about the neomutt-devel mailing list