switch statement using unsigned integer value

Started by Ron Pinkas, November 27, 2005, 09:10:44 PM

Previous topic - Next topic

Ron Pinkas

Follwoing sample produces what appears to be wrong result, compared to MSVC.

//---------------------------------------------------------//
#include <stdio.h>

void main( char argc, char *argv[] )
{
   unsigned int number = 0x80000002;

   switch( number )
   {
       case 0 :
           printf( "Error 0: %i", number );
           break;

       case 1 :
           printf( "Error 1: %i", number );
           break;

       case 2 :
           printf( "Error 2: %i", number );
           break;

       case 3 :
           printf( "Error 3: %i", number );
           break;
 
       default :
           printf( "Good: %i", number );
   }
}
//---------------------------------------------------------//

Ron

[P.S. Pelle, I'm still not able to contact your private email. Could you please advise how I could contact you?]

Ron Pinkas

The following variation (tested with latest 4.0) even causes a GPF:

//----------------------------------------------------//
#include <stdio.h>

void test( unsigned int number );

void main( char argc, char *argv[] )
{
  long number;

  number = 0x80000002;
  test( number );

  number = 0xF0000002;
  test( number );
}

void test( unsigned int number )
{
   switch( number )
   {
       case 0 :
           printf( "Error 0: %i", number );
           break;

       case 1 :
           printf( "Error 1: %i", number );
           break;

       case 2 :
           printf( "Error 2: %i", number );
           break;

       case 3 :
           printf( "Error 3: %i", number );
           break;

       default :
           printf( "Good: %i", number );
   }
}
//----------------------------------------------------//

Ron

Ron Pinkas

FWIW, declaring number as:

  unsigned int number;

makes no difference, and the source compiles without any warning, when using level 1 warning.

[Attached the actual source file.]

Ron

Greg

Ron,

This is the same problem as posted here. Are you the same person? FWIW,  I replied there.

Ron Pinkas

Hi Greg,

"This is the same problem as posted here. Are you the same person? FWIW, I replied there."

Sorry, I don't understand, "here" and "there". I posted 3 messages , all about the same topic, and all right here, in this thread.

Ron

Robert

Quote from: "Greg"Ron,

This is the same problem as posted here. Are you the same person? FWIW,  I replied there.

The word "here", above,  is a link to the URL

http://smorgasbordet.com/phpBB2/viewtopic.php?t=915

where Guerra000 (Vic) posted the same question.

Robert Wishlaw

Ron Pinkas

Robert, Greg,

[Sorry, I somehow missed the link.]

No I'm not the same person, but Vic is a customer of mine, and I was not made aware that he already posted the issue. My apologies for the redundancy.

Ron

guerra000

Quote from: "Greg"Ron,

This is the same problem as posted here. Are you the same person? FWIW,  I replied there.

I'm sorry. I posted the same bug in other forum. I hadn't seen this (bug reports) forum.

Atte.
Vic

guerra000

Quote from: "Greg"Ron,

This is the same problem as posted here. Are you the same person? FWIW,  I replied there.

I'm sorry. I posted the same bug in other forum. I hadn't seen this (bug reports) forum.

Atte.
Vic