* Andrew Haley: > On 08/21/2010 10:43 AM, Florian Weimer wrote: >> * H. J. Lu: >> >>> Sometime I have to do >>> >>> int x = 0; >>> >>> to silence gcc from uninitialized warnings when I know it is >>> unnecessary. >> >> I guess the official idiom is >> >> int x = x; >> >> and it is somewhat used in the GNU project although it is not >> portable. > > Ewww, yuck. I think this'll get a read from uninitialized message from > Valgrind. It's undefined behaviour too.
GCC has specific code to deal with this construct. I don't think the undefined load will actually end up in machine code, so valgrind won't see it. And while it is undefined according to the standard (that's why I called it not portable), it appears to be a supported GCC extension. (This is based on the existance of the -Wself-init option, it's not explicitly documented as an extension AFAICT.) That being said, I don't like it, either.