C question

From: George Necula (necula@EECS.Berkeley.EDU)
Date: 01/07/01


Message-ID: <DE2CF556E37E0949BBCA86854480EDAE16E0D8@JANUS.eecs.berkeley.edu>
From: George Necula <necula@EECS.Berkeley.EDU>
Subject: C question
Date: Sun, 7 Jan 2001 13:49:21 -0800 


 I have encountered a strange problem with a little C program:

int foo(int n, int m) {
  if (n < sizeof(int)) ...
  if (n < (1 << sizeof(int))) ...
}

 According to the (ISO) specification sizeof is always unsigned, so the
first comparison must be unsigned! But the type of the << operator is the
type of the left operand, so the second comparison should be signed!

 GCC implements exactly this but MSVC implements the second comparison
unsigned. Does any of you have access to K&R or ANSI to see whether this is
undefined behavior or just a bug in MSVC.

George.



This archive was generated by hypermail 2b30 : 11/04/02 PST