This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: warning: '<some_var>' may be used uninitialized in this function


Because best.score is set to 0 up front, he is expecting the || (or) to short circuit and never test best.d.

But... getting a compiler to figure that out is expecting too much. Did you try up'ing the optimization level (just out of curiosity)?


On Jan 12, 2006, at 9:01 AM, Diego Novillo wrote:


On Thursday 12 January 2006 09:53, Christian.Iseli@licr.org wrote:

On my FC4 box with gcc version 4.0.2 20051125 (Red Hat 4.0.2-8) it says:
testit.c: In function 'testit':
testit.c:6: warning: 'best.d' may be used uninitialized in this function


The warning is valid.  You are not guaranteeing that best.d will be
initialized.  What if all the values in array 'a' are < 0?

Your best bet is

struct {int score; int d;} best = {0,0};



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]