<p dir="ltr"><br>
On Apr 19, 2016 6:10 PM, "Emil Velikov" <<a href="mailto:emil.l.velikov@gmail.com">emil.l.velikov@gmail.com</a>> wrote:<br>
><br>
> On 19 April 2016 at 23:18, Chad Versace <<a href="mailto:chad.versace@intel.com">chad.versace@intel.com</a>> wrote:<br>
> > 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>
> > 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>
> ><br>
> Almost... this won't play nice with C++ contexts. There's also the<br>
> fact that some C compilers will bark at us if we nest something within<br>
> the isl_extend2d struct, despite that the c99 standard (or was it c89)<br>
> is pretty clear that the above is sufficient.<br>
><br>
> Namely it will complain that we need another set of brackets. Check<br>
> out the GCC bug [1] about this.</p>
<p dir="ltr">I added more brackets. :-)</p>
<p dir="ltr">> So yes, it's annoyingly long/verbose solution but for a reason ;-)<br>
> -Emil<br>
><br>
> [1] <a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119</a><br>
</p>