Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!burl!codas!mtune!westmark!dave From: dave@westmark.UUCP Newsgroups: comp.lang.c,comp.sys.ibm.pc Subject: What's Wrong here? Message-ID: <278@westmark.UUCP> Date: Sat, 28-Nov-87 08:56:17 EST Article-I.D.: westmark.278 Posted: Sat Nov 28 08:56:17 1987 Date-Received: Mon, 30-Nov-87 06:52:06 EST Organization: Westmark, Inc., Warren, NJ, USA Lines: 28 Xref: utgpu comp.lang.c:5312 comp.sys.ibm.pc:9048 Perhaps a C guru on the net can tell me what's wrong with this trivial C program? #includemain() { long n; n = (1 << 31) -1; printf("%ld\n", n); } This is a simple example of a problem that affects a more complex piece of someone's software that I'm trying to maintain. If I compile this under UNIX, and run it, it prints 2147483647. If I compile this under MS-DOS using Microsoft C Rel 3.0, and run it, it gets the same answer!!! But if I compile it under MS-DOS using Microsoft C Rel 4.0, it prints 65535. Has anyone tried something like this under Microsoft C Rel 5.0? Am I mis-using C? Is there a reason why the expression is apparently evaluated as an int and then promoted to long in one compiler but evaluated as a long in two others? -- Dave Levenson Westmark, Inc. A node for news. Warren, NJ USA {rutgers | clyde | mtune | ihnp4}!westmark!dave