Dmitry:

Sorry, I was being lazy.  Here is a test routine that demonstrates the
weirdness.


#define LVAL 8
void test() {
  long a, b;
  int c;
  
  // Works
  printf ("TEST1\r\n");
  a = 0x12345678l;
  b = a >> LVAL;
  printf ("TEST: b = a >> %2d ---> 0x%08lx\r\n", LVAL, b);

  // Doesn't work for LVAL=8,16+
  printf ("TEST2\r\n");
  b = 0x12345678l;
  b >>= LVAL;
  printf ("TEST: b >>= %2d    ---> 0x%08lx\r\n", LVAL, b);

  // Works
  printf ("TEST3\r\n");
  b = 0x12345678l;
  c = LVAL;
  b >>= c;
  printf ("TEST: b >>= c     ---> 0x%08lx\r\n", b);
}


What I got:

LVAL = 8
========
TEST1
TEST: b = a >> 8 ---> 0x00123456
TEST2
TEST: b >>= 8    ---> 0x00124c56
TEST3
TEST: b >>= c    ---> 0x00123456

LVAL = 16
=========
TEST1
TEST: b = a >> 16 ---> 0x00001234
TEST2
TEST: b >>= 16    ---> 0x00000000
TEST3
TEST: b >>= c     ---> 0x00001234



Gotta go...  Any help will be appreciated.
Thanks,
-Paul

-----Original Message-----
From: Dmitry <[email protected]>
Date: Fri, 23 May 2003 22:06:38 +0400
Subject: Re: [Mspgcc-users] More shifting problems

diwil> constants are ints by default.
diwil> so, use sufix 'l' for them.
diwil> If you still got a problem, post sorces which cause a problem.
diwil> Form ones you posted, the shift operation should be eliminated.
diwil> ~d
diwil> 
diwil> 

Reply via email to