NO

Author Topic: switch statement using unsigned integer value  (Read 8403 times)

Ron Pinkas

  • Guest
switch statement using unsigned integer value
« 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?]

Ron Pinkas

  • Guest
switch statement using unsigned integer value
« Reply #1 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

Ron Pinkas

  • Guest
switch statement using unsigned integer value
« Reply #2 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

Greg

  • Guest
switch statement using unsigned integer value
« Reply #3 on: November 28, 2005, 12:15:36 AM »
Ron,

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

Ron Pinkas

  • Guest
switch statement using unsigned integer value
« Reply #4 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

Offline Robert

  • Member
  • *
  • Posts: 247
switch statement using unsigned integer value
« Reply #5 on: November 28, 2005, 01:49:17 AM »
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

  • Guest
switch statement using unsigned integer value
« Reply #6 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

guerra000

  • Guest
switch statement using unsigned integer value
« Reply #7 on: November 28, 2005, 04:29:26 AM »
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

  • Guest
switch statement using unsigned integer value
« Reply #8 on: November 28, 2005, 04:45:59 AM »
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