Re: [PATCH 1/3] cli: add insert --must-index option

Subject: Re: [PATCH 1/3] cli: add insert --must-index option

Date: Wed, 23 Oct 2013 21:05:33 -0300

To: Austin Clements, Tomi Ollila

Cc: notmuch@notmuchmail.org

From: David Bremner


Austin Clements <amdragon@MIT.EDU> writes:

> And in libnotmuch, we would do something like
>
> notmuch_status_t
> notmuch_database_open (const char *path,
>                        notmuch_database_mode_t mode,
>                        const notmuch_options_t *options,
>                        notmuch_database_t **database)
> {
>     notmuch_option_t real_options = NOTMUCH_OPTIONS_INIT;
>     if (real_options.options_length < options.options_length)
>         return error;
>     memmove(&real_options, options, options.options_length);
>     // ...
> }
>

Does the C standard guarantee that if two structs have the same initial
set of members, that they are aligned in a compatible way? I suppose it
must work, but I'm still curious.

Yet another approach would be to pass in array of descriptors, something
like the command line argument parsing code does now.

libnotmuch_opt_desc_t options[] = {
  { LIBNOTMUCH_OPT_LOGHOOK, loghook },
  { 0, 0} 
}

I guess passing a (void *) as the second element of the pair?

Of course it's a bit more work to unpack this way.

Thread: