[waffle] [PATCH 5/6] wflinfo: Distinguish between cmdline options and func options

Chad Versace chad.versace at linux.intel.com
Wed Apr 30 19:06:44 PDT 2014


On Mon, Apr 28, 2014 at 11:45:41PM -0700, Jordan Justen wrote:
> On Mon, Apr 28, 2014 at 8:43 PM, Chad Versace

> >  static bool
> > -wflinfo_try_create_context(const struct options *opts,
> > -                           struct waffle_display *dpy,
> > +wflinfo_try_create_context(struct waffle_display *dpy,
> > +                           struct wflinfo_config_attrs attrs,
> 
> I prefer pointers to structs for function parameters. (I don't like
> the implicit copy on call.)
> 
> But, either way:
> Reviewed-by: Jordan Justen <jordan.l.justen at intel.com>

I usually dislike pass-struct-by-value too. The original patch passed by
pointer, but it was messier than pass-by-value. The function calls
basically followed this pattern:

void
foo(const struct wflinfo_config_attrs *attrs)
{
    ...;

    struct wflinfo_config_attrs tmp_attrs = *attrs;
    tmp_attrs.version = abc;
    tmp_attrs.profile = xyz;
    bar(..., &tmp_attrs);
}

Passing by value simplified it to:

void
foo(struct wflinfo_config_attrs attrs)
{
    ...;

    attrs.version = abc;
    attrs.profile = xyz;
    bar(..., attrs);
}

Maybe the difference doesn't seem significant in this little example,
but in the real patch it looked a lot messier than the pass-by-value
idiom.


More information about the waffle mailing list