From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4296 invoked by alias); 10 Aug 2012 08:20:55 -0000 Received: (qmail 3999 invoked by uid 22791); 10 Aug 2012 08:20:52 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_NUMERIC_HELO,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from plane.gmane.org (HELO plane.gmane.org) (80.91.229.3) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Aug 2012 08:20:41 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SzkSV-0005nb-JC for gcc-help@gcc.gnu.org; Fri, 10 Aug 2012 10:20:39 +0200 Received: from 79.161.10.130 ([79.161.10.130]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Aug 2012 10:20:39 +0200 Received: from david by 79.161.10.130 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 10 Aug 2012 10:20:39 +0200 To: gcc-help@gcc.gnu.org From: David Brown Subject: Re: 16-bit int Date: Fri, 10 Aug 2012 08:35:00 -0000 Message-ID: <5024C255.7030504@westcontrol.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: "gcc-help@gcc.gnu.org" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: 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: 2012-08/txt/msg00071.txt.bz2 Message-ID: <20120810083500.PArYPIm7BwLM-Hvbwk7MhcWHI9gdrvVptytzBf87AJ0@z> On 10/08/2012 09:15, Göran Steen wrote: > Thank you for your response. > > I want to make sure that my code snippets, if they are compiled and > run on a machine with 16-bit int, still works. I don't have access to > such a machine, so I want to compile and run them with 16-bit int on > my machine that defaults to 32-bit int. Especially the intermediate > results' size are interesting. What happens if they are truncated to > 16-bit? > The answer here is simple - #include , and use types like int_fast16_t. If intermediary results might need 32 bits, cast to int_fast32_t as needed. On a target with 32-bit ints, both these types will normally be 32-bit (though int_fast16_t could theoretically be 16-bit), and the cast will do nothing. On a target with 16-bit ints, you will get 16-bit and 32-bit ints respectively. This will give you optimal code for all sizes of target ints, while also being correct on each target. mvh., David > There will not be any problem with library compatibility. > > BR /göran > > -----Original Message----- From: David Brown > [mailto:david@westcontrol.com] Sent: den 9 augusti 2012 15:37 To: > Göran Steen Cc: gcc-help@gcc.gnu.org Subject: Re: 16-bit int > > On 09/08/2012 13:26, Göran Steen wrote: >> Hi! >> >> I use gcc version 4.3.4, where int is 32-bit variables. Is it >> possible to setup compiler to compile int as 16-bit variables? >> >> With best regards / Med vänlig hälsning / Mit freundlichen Grüßen >> / Saudações >> >> Göran Steen > > > The size of an int depends on the target - gcc supports dozens of > targets. Most have 32-bit ints, but some have 16-bit ints and at > least one has a compile-time option to support 8-bit ints (though > that goes against C standards, and is deprecated on current builds). > There are probably also targets with 64-bit ints. > > So step one in asking for help here is to tell us your target. > > Step two is to tell us what you are hoping to achieve. Almost > certainly, there is no way to change the int size - and even if there > happens to be a command-line switch for the given target, it is > probably not a good idea (you'll get in a horrible mess with library > compatibility, for example). And even if it is possible, it is > highly unlikely to be advantageous. Tell us what you really want to > achieve here, and people can give you advice towards that. > > mvh., > > David >