public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* unitialised error
@ 2004-07-01 12:05 Ken Foskey
  2004-07-01 16:22 ` llewelly
  2004-07-01 20:48 ` Falk Hueffner
  0 siblings, 2 replies; 6+ messages in thread
From: Ken Foskey @ 2004-07-01 12:05 UTC (permalink / raw)
  To: gcc help


The following code gives me an uninitialised warning on nCol.  There is
no possible default clause for this one.

switch( nXIndex & 3 )
{
	case 0 :
		nCol = *pTmp >> 6;
		break;
	case 1 :
		nCol = ( *pTmp >> 4 ) & 0x03 ;
		break;

	case 2 :
		nCol = ( *pTmp >> 2 ) & 0x03;
		break;
	case 3 :
		nCol = ( *pTmp++ ) & 0x03;
		break;
}


-- 
Thanks
KenF
OpenOffice.org developer

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unitialised error
  2004-07-01 12:05 unitialised error Ken Foskey
@ 2004-07-01 16:22 ` llewelly
  2004-07-01 20:48 ` Falk Hueffner
  1 sibling, 0 replies; 6+ messages in thread
From: llewelly @ 2004-07-01 16:22 UTC (permalink / raw)
  To: Ken Foskey; +Cc: gcc help

Ken Foskey <foskey@optushome.com.au> writes:

> The following code gives me an uninitialised warning on nCol.  There is
> no possible default clause for this one.
> 
> switch( nXIndex & 3 )
> {
> 	case 0 :
> 		nCol = *pTmp >> 6;
> 		break;
> 	case 1 :
> 		nCol = ( *pTmp >> 4 ) & 0x03 ;
> 		break;
> 
> 	case 2 :
> 		nCol = ( *pTmp >> 2 ) & 0x03;
> 		break;
> 	case 3 :
> 		nCol = ( *pTmp++ ) & 0x03;
> 		break;
> }

What version of gcc are you using? I don't get any such warning for this
    code with gcc 2.95.3, 3.3.3 or 3.4 .

I completed it like this:

int main()
  {
    int nXIndex;
    int nCol;
    int Tmp;
    int *pTmp;
    switch( nXIndex & 3 )
    {
      case 0 :
        nCol = *pTmp >> 6;
        break;
      case 1 :
        nCol = ( *pTmp >> 4 ) & 0x03 ;
        break;

      case 2 :
        nCol = ( *pTmp >> 2 ) & 0x03;
        break;
      case 3 :
        nCol = ( *pTmp++ ) & 0x03;
        break;
    }

    Tmp= nCol;

  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unitialised error
  2004-07-01 12:05 unitialised error Ken Foskey
  2004-07-01 16:22 ` llewelly
@ 2004-07-01 20:48 ` Falk Hueffner
  2004-07-02  5:35   ` llewelly
  1 sibling, 1 reply; 6+ messages in thread
From: Falk Hueffner @ 2004-07-01 20:48 UTC (permalink / raw)
  To: Ken Foskey; +Cc: gcc help

Ken Foskey <foskey@optushome.com.au> writes:

> The following code gives me an uninitialised warning on nCol.  There is
> no possible default clause for this one.
>
> switch( nXIndex & 3 )
> {
> 	case 0 :
> 		nCol = *pTmp >> 6;
> 		break;
> 	case 1 :
> 		nCol = ( *pTmp >> 4 ) & 0x03 ;
> 		break;
>
> 	case 2 :
> 		nCol = ( *pTmp >> 2 ) & 0x03;
> 		break;
> 	case 3 :
> 		nCol = ( *pTmp++ ) & 0x03;
> 		break;
> }

There will always be cases where gcc guesses wrong on this; it is not
only very hard, but provably impossible to get it always right.

In this case however, it indicates an optimizer deficiency. You could
try to file a bug report about it.

By the way, please always post complete test cases and include version
and command line options.

-- 
	Falk

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unitialised error
  2004-07-01 20:48 ` Falk Hueffner
@ 2004-07-02  5:35   ` llewelly
  2004-07-02  8:03     ` Ken Foskey
  0 siblings, 1 reply; 6+ messages in thread
From: llewelly @ 2004-07-02  5:35 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: Ken Foskey, gcc help

Falk Hueffner <hueffner@informatik.uni-tuebingen.de> writes:

> Ken Foskey <foskey@optushome.com.au> writes:
> 
> > The following code gives me an uninitialised warning on nCol.  There is
> > no possible default clause for this one.
> >
> > switch( nXIndex & 3 )
> > {
> > 	case 0 :
> > 		nCol = *pTmp >> 6;
> > 		break;
> > 	case 1 :
> > 		nCol = ( *pTmp >> 4 ) & 0x03 ;
> > 		break;
> >
> > 	case 2 :
> > 		nCol = ( *pTmp >> 2 ) & 0x03;
> > 		break;
> > 	case 3 :
> > 		nCol = ( *pTmp++ ) & 0x03;
> > 		break;
> > }
> 
> There will always be cases where gcc guesses wrong on this; it is not
> only very hard, but provably impossible to get it always right.


However I get no such warnings for the same code, not with gcc 3.4,
    3.3.3, or very old 2.95.3 .

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unitialised error
  2004-07-02  5:35   ` llewelly
@ 2004-07-02  8:03     ` Ken Foskey
  2004-07-02 13:45       ` llewelly
  0 siblings, 1 reply; 6+ messages in thread
From: Ken Foskey @ 2004-07-02  8:03 UTC (permalink / raw)
  To: gcc help

On Fri, 2004-07-02 at 15:35, llewelly@xmission.com wrote:

> However I get no such warnings for the same code, not with gcc 3.4,
>     3.3.3, or very old 2.95.3 .

You need to turn on optimisation and  -Wuninitialized

Very good practice,  I have found lots of bugs this way.

-- 
Thanks
KenF
OpenOffice.org developer

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: unitialised error
  2004-07-02  8:03     ` Ken Foskey
@ 2004-07-02 13:45       ` llewelly
  0 siblings, 0 replies; 6+ messages in thread
From: llewelly @ 2004-07-02 13:45 UTC (permalink / raw)
  To: Ken Foskey; +Cc: gcc help

Ken Foskey <foskey@optushome.com.au> writes:

> On Fri, 2004-07-02 at 15:35, llewelly@xmission.com wrote:
> 
> > However I get no such warnings for the same code, not with gcc 3.4,
> >     3.3.3, or very old 2.95.3 .
> 
> You need to turn on optimisation and  -Wuninitialized

I had optimization and -Wuninitialized. Here was the full compile
line:

cd /home/llewelly/llewelly/cc_moderated/
g++-3.4 -O2 -W -Wall -Wuninitialized foskey.cc

Compilation finished at Fri Jul  2 07:41:03


(I just re-verified)

Maybe the surrounding code you didn't paste affected the diagnostic. I
completed your original example like this:


int main()
  {
    int nXIndex;
    int nCol;
    int Tmp;
    int *pTmp;
    switch( nXIndex & 3 )
    {
      case 0 :
        nCol = *pTmp >> 6;
        break;
      case 1 :
        nCol = ( *pTmp >> 4 ) & 0x03 ;
        break;

      case 2 :
        nCol = ( *pTmp >> 2 ) & 0x03;
        break;
      case 3 :
        nCol = ( *pTmp++ ) & 0x03;
        break;
    }

    Tmp= nCol;

  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-07-02 13:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-01 12:05 unitialised error Ken Foskey
2004-07-01 16:22 ` llewelly
2004-07-01 20:48 ` Falk Hueffner
2004-07-02  5:35   ` llewelly
2004-07-02  8:03     ` Ken Foskey
2004-07-02 13:45       ` llewelly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).