Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #35359

Re: Suitable type names needed for portable integers

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Suitable type names needed for portable integers
Date 2013-08-15 17:49 -0400
Organization Self
Message-ID <520D4CD7.7060002@verizon.net> (permalink)
References <kujhhj$i1t$1@dont-email.me>

Show all headers | View raw


On 08/15/2013 05:34 PM, James Harris wrote:
> I am working on code that is to run on 16-bit, 32-bit and 64-bit machines 
> and am looking for a way to declare specific types of integers. Could you 
> suggest suitable names for the following?
> 
> 1. Integers which will be 16-bit on 16-bit machines and 32-bit on both 
> 32-bit machines and 64-bit machines.
> 
> 2. Integers which will be 16-bit on 16-bit machines, 32-bit on 32-bit 
> machines and 64-bit on 64-bit machines.
> 
> Both of these types need at least signed and unsigned variants so the need 
> is for exactly four type names:
> 
>   a name for   signed 16, 32, 32
>   a name for unsigned 16, 32, 32
> 
>   a name for   signed 16, 32, 64
>   a name for unsigned 16, 32, 64
> 
> I intend to define these names explicitly so that they are not subject to 
> the defaults of any given compiler. So I don't want to use int, for example. 
> I was going to use sint and uint as two of the names but one compiler 
> predefines uint ... which is a pain. So I am looking for something else. All 
> that's needed are four names. Any suggestions? Any precedent?

I suspect that you've made a decision about how to achieve a goal, and
are trying to figure out how to implement that decision, when what you
really should be doing is reconsidering that decision. I suspect I could
recommend a better way of achieving that goal, if I knew what it was. So
far, you've described your decision, but not the goal it's intended to
achieve.

The <stdint.h> header that was added in C99 provides three pairs of
families of type names: [u]intN_t, [u]int_leastN_t, and [u]int_fastN_t.

For example, int_fast16_t is the fastest signed integer type that has at
least 16  bits. uint_least32_t is the smallest unsigned integer type
that has at least 32 bits. int64_t is an signed integer type with
exactly 64 bits.
The "least" and "fast" types are required to be supported for N=8, 16,
32, and 64. The exact-sized types are optional. The relevant names are
reserved for all values of N - you're not likely to need int_least39_t,
but if you find a implementation that uses that name, they're required
to use it to describe the smallest type with at least 39 bits.
You can determine which of the optional types is supported by using, for
example:

#ifdef INT32_MAX

Would any of these types serve your purpose? Note that, in particular,
int_fast16_t could be a 64 bit type on a 64 bit machine.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-15 22:34 +0100
  Re: Suitable type names needed for portable integers James Kuyper <jameskuyper@verizon.net> - 2013-08-15 17:49 -0400
    Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 01:51 +0100
      Re: Suitable type names needed for portable integers Dr Nick <nospam-4@temporary-address.org.uk> - 2013-08-16 08:07 +0100
      Re: Suitable type names needed for portable integers christian.bau@cbau.wanadoo.co.uk - 2013-08-16 03:14 -0700
        Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 11:34 +0100
      Re: Suitable type names needed for portable integers David Brown <david@westcontrol.removethisbit.com> - 2013-08-16 14:19 +0200
        Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 14:21 +0100
        Re: Suitable type names needed for portable integers Robert Wessel <robertwessel2@yahoo.com> - 2013-08-16 10:24 -0500
        Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-16 09:15 -0700
          Re: Suitable type names needed for portable integers David Brown <david.brown@removethis.hesbynett.no> - 2013-08-18 17:17 +0200
          Re: Suitable type names needed for portable integers Roberto Waltman <usenet@rwaltman.com> - 2013-08-19 21:02 -0400
    Re: Suitable type names needed for portable integers falk@rahul.net (Edward A. Falk) - 2013-08-19 20:44 +0000
      Re: Suitable type names needed for portable integers James Kuyper <jameskuyper@verizon.net> - 2013-08-19 17:05 -0400
        Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-19 23:02 +0100
        Re: Suitable type names needed for portable integers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-20 14:46 -0700
          Re: Suitable type names needed for portable integers jadill33@gmail.com - 2013-08-20 15:20 -0700
  Re: Suitable type names needed for portable integers christian.bau@cbau.wanadoo.co.uk - 2013-08-15 17:18 -0700
  Re: Suitable type names needed for portable integers "BartC" <bc@freeuk.com> - 2013-08-16 09:08 +0100
    Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 10:16 +0100
    Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-16 09:03 -0700
      Re: Suitable type names needed for portable integers Nick Bowler <nbowler@draconx.ca> - 2013-08-16 16:53 +0000
        Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-16 10:45 -0700
      Re: Suitable type names needed for portable integers James Kuyper <jameskuyper@verizon.net> - 2013-08-16 13:04 -0400
  Re: Suitable type names needed for portable integers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-16 03:40 -0700
    Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 12:51 +0100
  Re: Suitable type names needed for portable integers Ian Pilcher <arequipeno@gmail.com> - 2013-08-16 13:31 -0500
    Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-16 22:37 +0100
      Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-16 17:12 -0700
        Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-17 08:13 +0100
          Re: Suitable type names needed for portable integers James Kuyper <jameskuyper@verizon.net> - 2013-08-17 08:58 -0400
  Re: Suitable type names needed for portable integers jadill33@gmail.com - 2013-08-20 12:16 -0700
    Re: Suitable type names needed for portable integers James Kuyper <jameskuyper@verizon.net> - 2013-08-20 15:50 -0400
      Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-20 13:45 -0700
        Re: Suitable type names needed for portable integers Keith Thompson <kst-u@mib.org> - 2013-08-20 16:07 -0700
      Re: Suitable type names needed for portable integers jadill33@gmail.com - 2013-08-20 14:22 -0700
        Re: Suitable type names needed for portable integers "James Harris" <james.harris.1@gmail.com> - 2013-08-23 09:10 +0100
  Re: Suitable type names needed for portable integers Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-20 22:17 -0700

csiph-web