On Tue, 2016-09-27 at 13:26 -0400, Robbie Harwood wrote:
Nathaniel McCallum <npmccallum(a)redhat.com> writes:
> On Tue, 2016-09-27 at 11:08 -0400, Simo Sorce wrote:
> > On Tue, 2016-09-27 at 09:13 -0400, Nathaniel McCallum wrote:
> >
> > > Why doesn't "gssx_cred remote = {};" work?
> >
> >
> > I know it should work, and do not know why it didn't, but I
> > pushed
> > this patch anyway, I can put in something better later as long as
> > clang does not complain.
>
>
> I suspect that clang is complaining because zero isn't the right
> value
> for the first field of gssx_cred. Simply removing that one byte
> should
> be sufficient to make clang happy.
>
> What is the actual complaint?
Clang says this:
> src/mechglue/gpp_creds.c:186:29: warning: suggest braces around
> initialization of subobject [-Wmissing-braces]
> gssx_cred remote = {0};
> ^
> {}
> src/mechglue/gpp_creds.c:186:29: warning: suggest braces around
> initialization of subobject [-Wmissing-braces]
> gssx_cred remote = {0};
> ^
> {}
> 2 warnings generated.
and it's warning twice because what it wants to see is `gssx_cred
remote
= {{{0}}};`. Given the choice, I prefer the memset() to this
notation.
Did you try taking the zero out?
I've seen this idiom before in our group and it (almost) never makes
sense. {0} attempts to initialize the first scalar field to zero. It is
functionally identical to {} when the first field of the struct is a
scalar. But it often isn't. When the first field is, say, a struct, {0}
is a syntax error.
C99 defines that when using an initializer, any unspecified fields are
initialized to zero. Thus, {} is perfectly valid for all cases when
initializing a struct to zero.
Using an empty initializer should be preferred because the compiler can
simply align all the zeroed stack variables and do a single zero for
all of them. Using memset() is harder to optimize this way.
Nathaniel