From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30655 invoked by alias); 19 Aug 2008 13:24:34 -0000 Received: (qmail 30642 invoked by uid 22791); 19 Aug 2008 13:24:32 -0000 X-Spam-Check-By: sourceware.org Received: from exprod6og105.obsmtp.com (HELO exprod6og105.obsmtp.com) (64.18.1.189) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 19 Aug 2008 13:23:35 +0000 Received: from source ([192.150.8.22]) by exprod6ob105.postini.com ([64.18.5.12]) with SMTP; Tue, 19 Aug 2008 06:23:28 PDT Received: from inner-relay-3.eur.adobe.com (inner-relay-3b [10.128.4.236]) by outbound-smtp-2.corp.adobe.com (8.12.10/8.12.10) with ESMTP id m7JDNQE0008261; Tue, 19 Aug 2008 06:23:27 -0700 (PDT) Received: from apacmail.pac.adobe.com (apacmail.pac.adobe.com [130.248.36.99]) by inner-relay-3.eur.adobe.com (8.12.10/8.12.9) with ESMTP id m7JDNMqJ018017; Tue, 19 Aug 2008 06:23:24 -0700 (PDT) Received: from namailgen.corp.adobe.com ([10.8.192.91]) by apacmail.pac.adobe.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 19 Aug 2008 22:23:21 +0900 Received: from 10.7.234.18 ([10.7.234.18]) by namailgen.corp.adobe.com ([10.8.192.91]) via Exchange Front-End Server namail.corp.adobe.com ([10.8.189.97]) with Microsoft Exchange Server HTTP-DAV ; Tue, 19 Aug 2008 13:23:20 +0000 User-Agent: Microsoft-Entourage/12.12.0.080729 Date: Tue, 19 Aug 2008 15:35:00 -0000 Subject: Re: regarding type promotion From: Eljay Love-Jensen To: "Sivaprasad.pv" , GCC-help Message-ID: In-Reply-To: <48AA5377.9080001@redpinesignals.com> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00167.txt.bz2 Hi Siva, > If we consider following sample C language code : > > long long int k=0x123; > int p=1; > k = k + p << 33; > > Here the value in variable 'p' is shifted by 33 and then the result > (only 32 bit result)was promoted to 64 bit. Yes, that's correct. ((k) = ((k) + ((p) << (33)))); Using L to mark long long, and I to mark int, and @ to mark promotion: L(L(k) = L(L(k) + L@(I(I(p) << I(33))))); Also note that where int is 32-bit, doing a i << 33 is undefined behavior. It could shift to zero. It could leave the number as-is. It could shift by one. It could... DESTROY THE UNIVERSE. So be careful with that. (If shifting a 32-bit int by 33 with GCC does destroy the universe, please file a bug .) > Is it an expected behavior? Yes. > Is there any way to specify in gcc to perform implicit type promotion > first and then perform operation on it (without explicit type casting). Yes. long long k=0x123; // <-- implicit promotion 0x123 --> 0x123LL long long p=1; // <-- implicit promotion 1 --> 1LL k = k + p << 33; HTH, --Eljay