<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 3:18 PM, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@intel.com" target="_blank">chad.versace@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Tue 19 Apr 2016, Emil Velikov wrote:<br>
> On 16 April 2016 at 20:45, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> > C++ doesn't support designated initializers and g++ in particular doesn't<br>
> > handle them when the struct gets complicated, i.e. has a union.<br>
> > ---<br>
> > src/intel/isl/isl.h | 32 ++++++++++++++++++++------------<br>
> > 1 file changed, 20 insertions(+), 12 deletions(-)<br>
> ><br>
> > diff --git a/src/intel/isl/isl.h b/src/intel/isl/isl.h<br>
> > index 33d43d7..c3a1106 100644<br>
> > --- a/src/intel/isl/isl.h<br>
> > +++ b/src/intel/isl/isl.h<br>
> > @@ -988,25 +988,35 @@ isl_surf_info_is_z32_float(const struct isl_surf_init_info *info)<br>
> > static inline struct isl_extent2d<br>
> > isl_extent2d(uint32_t width, uint32_t height)<br>
> > {<br>
> > - return (struct isl_extent2d) { .w = width, .h = height };<br>
> > + struct isl_extent2d e = {<br>
> > + { width, },<br>
> > + { height, },<br>
> > + };<br>
> > + return e;<br>
> > }<br>
> ><br>
> Please use something like the following<br>
><br>
> struct isl_extent2d e;<br>
><br>
> memset(&e, 0, sizeof(e));<br>
> e.w = width;<br>
> e.h = height;<br>
><br>
> return e;<br>
><br>
> It is a bit over expressive to write/look at, although it will give<br>
> you exactly what you want _all_ the time.<br>
> Otherwise you risk feeding garbage and/or setting the wrong struct<br>
> member as isl_extent2d change.<br>
><br>
> Hunting bugs that this may cause, is not what you want to do. Plus the<br>
> compiler will optimise it to the exact same code.<br>
<br>
</div></div>I agree with Emil. Let's use explicit member names when initializing the<br>
structs. But, the memset isn't needed. The below initializaing pattern<br>
is more concise and *safer*, as it doesn't requiring typing the struct<br>
size.<br>
<br>
struct isl_extent2d e = {0};<br>
<div class="HOEnZb"><div class="h5"><br>
e.w = width;<br>
e.h = height;<br>
<br>
return e;<br>
</div></div></blockquote></div><br></div><div class="gmail_extra">Done<br></div></div>