Pelles C forum

Pelles C => Bug reports => Topic started by: Ron Pinkas on November 27, 2005, 09:10:44 PM

Title: switch statement using unsigned integer value
Post by: Ron Pinkas on November 27, 2005, 09:10:44 PM
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?]
Title: switch statement using unsigned integer value
Post by: Ron Pinkas on November 27, 2005, 10:21:57 PM
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
Title: switch statement using unsigned integer value
Post by: Ron Pinkas on November 27, 2005, 10:27:49 PM
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
Title: switch statement using unsigned integer value
Post by: Greg on November 28, 2005, 12:15:36 AM
Ron,

This is the same problem as posted here (http://smorgasbordet.com/phpBB2/viewtopic.php?t=915). Are you the same person? FWIW,  I replied there.
Title: switch statement using unsigned integer value
Post by: Ron Pinkas on November 28, 2005, 12:57:25 AM
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
Title: switch statement using unsigned integer value
Post by: Robert on November 28, 2005, 01:49:17 AM
Quote from: "Greg"Ron,

This is the same problem as posted here (http://smorgasbordet.com/phpBB2/viewtopic.php?t=915). 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
Title: switch statement using unsigned integer value
Post by: Ron Pinkas on November 28, 2005, 03:31:33 AM
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
Title: switch statement using unsigned integer value
Post by: guerra000 on November 28, 2005, 04:29:26 AM
Quote from: "Greg"Ron,

This is the same problem as posted here (http://smorgasbordet.com/phpBB2/viewtopic.php?t=915). 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
Title: switch statement using unsigned integer value
Post by: guerra000 on November 28, 2005, 04:45:59 AM
Quote from: "Greg"Ron,

This is the same problem as posted here (http://smorgasbordet.com/phpBB2/viewtopic.php?t=915). 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