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


Groups > comp.lang.c > #34954

Re: 64-bit integers where the implementation supports max 32-bit ints

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: 64-bit integers where the implementation supports max 32-bit ints
Date 2013-08-05 18:42 -0700
Organization None to speak of
Message-ID <lnfvunsigr.fsf@nuthaus.mib.org> (permalink)
References <ktolnp$lkb$1@dont-email.me> <lnwqo0rldz.fsf@nuthaus.mib.org> <ktp5ik$k02$1@dont-email.me>

Show all headers | View raw


"James Harris" <james.harris.1@gmail.com> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message 
> news:lnwqo0rldz.fsf@nuthaus.mib.org...
[...]
> FWIW the section of the header which defines the 64-bit types is currently 
> as follows. It's not fully tested yet.
>
> /*
>  * 64-bit integers
>  */
>
> #if INT_MAX == 0x7fffffffffffffff
>   typedef signed int s64_t;
> #elif LONG_MAX == 0x7fffffffffffffff
>   typedef signed long s64_t;
> #elif LLONG_MAX == 0x7fffffffffffffff
>   typedef signed long long s64_t;
> #else
>   typedef struct {u32_t low; s32_t high;} s64_t; /* Limited use */
> #endif

This might cause problems if the 16-bit compiler's preprocessor can't
handle a 64-bit constant like 0x7fffffffffffffff.  I'm not sure there's
a really good solution.  But it's likely you'll only get some warnings,
and you can ignore them as long as it selects the right definition.

[...]
>> The name "uint32_t" was added by the same standard (C99) that mandated
>> the existence of "long long".  Do you have a C90 compiler that supports
>> uint32_t as an extension?  If not, you might need to define uint32_t
>> yourself.
>
> The 16-bit compiler doesn't have those definitions but the 32-bit compiler 
> does. So I have chosen different names and come up with a header which 
> includes the following. There are similar sections for other integer widths. 
> The 32-bit stuff is simpler than that for 64-bit, above.

Hmm.  Personally, I'd be inclined to use the *same* names defined by
C99.

Some years ago, Doug Gwyn wrote a collection of files under the name
"q8" which provide an implementation of C99-specific headers (including
<stdint.h> for use with pre-C99 compilers.  They're public domain, so
feel free to use them any way you like.

For example:

#if _STDC_VERSION__ >= 199901L
#include <stdint.h>
#else
#include <mystdint.h>
#endif

You can then freely use uint32_t and friends (except, of course, that
your uint64_t won't directly support arithmetic operations).

[...]

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-05 18:07 +0100
  Re: 64-bit integers where the implementation supports max 32-bit ints Shao Miller <sha0.miller@gmail.com> - 2013-08-05 13:16 -0400
  Re: 64-bit integers where the implementation supports max 32-bit ints glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2013-08-05 18:57 +0000
  Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-05 12:24 -0700
    Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-05 22:37 +0100
      Re: 64-bit integers where the implementation supports max 32-bit ints Robert Wessel <robertwessel2@yahoo.com> - 2013-08-05 20:20 -0500
        Re: 64-bit integers where the implementation supports max 32-bit ints Robert Wessel <robertwessel2@yahoo.com> - 2013-08-05 23:34 -0500
      Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-05 18:42 -0700
        Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-06 11:15 +0100
          Re: 64-bit integers where the implementation supports max 32-bit ints James Kuyper <jameskuyper@verizon.net> - 2013-08-06 08:00 -0400
            Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-06 13:59 +0100
              Re: 64-bit integers where the implementation supports max 32-bit ints James Kuyper <jameskuyper@verizon.net> - 2013-08-06 09:31 -0400
                Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-06 15:12 +0100
                Re: 64-bit integers where the implementation supports max 32-bit ints Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-06 07:19 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-06 08:43 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Ian Collins <ian-news@hotmail.com> - 2013-08-07 15:51 +1200
                Re: 64-bit integers where the implementation supports max 32-bit ints Stephen Sprunk <stephen@sprunk.org> - 2013-08-06 21:48 -0500
                Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-07 11:11 +0100
                Re: 64-bit integers where the implementation supports max 32-bit ints Stephen Sprunk <stephen@sprunk.org> - 2013-08-07 05:46 -0500
                Re: 64-bit integers where the implementation supports max 32-bit ints Rosario1903 <Rosario@invalid.invalid> - 2013-08-07 17:38 +0200
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-07 09:27 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Rosario1903 <Rosario@invalid.invalid> - 2013-08-07 18:36 +0200
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-07 10:04 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Rosario1903 <Rosario@invalid.invalid> - 2013-08-07 19:49 +0200
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-07 11:13 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2013-08-07 12:37 -0600
                Re: 64-bit integers where the implementation supports max 32-bit ints Rosario1903 <Rosario@invalid.invalid> - 2013-08-07 19:46 +0200
                Re: 64-bit integers where the implementation supports max 32-bit ints Stephen Sprunk <stephen@sprunk.org> - 2013-08-08 01:17 -0500
                Re: 64-bit integers where the implementation supports max 32-bit ints Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2013-08-08 09:54 +0300
                Re: 64-bit integers where the implementation supports max 32-bit ints Rosario1903 <Rosario@invalid.invalid> - 2013-08-08 16:38 +0200
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-08 08:27 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-07 09:05 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-07 03:48 -0700
                Re: 64-bit integers where the implementation supports max 32-bit ints James Kuyper <jameskuyper@verizon.net> - 2013-08-06 11:55 -0400
                Re: 64-bit integers where the implementation supports max 32-bit ints Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-06 21:21 +0100
          Re: 64-bit integers where the implementation supports max 32-bit ints Keith Thompson <kst-u@mib.org> - 2013-08-06 08:38 -0700
        Re: 64-bit integers where the implementation supports max 32-bit ints "James Harris" <james.harris.1@gmail.com> - 2013-08-06 12:15 +0100
        Re: 64-bit integers where the implementation supports max 32-bit ints Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-06 09:36 -0400
          Re: 64-bit integers where the implementation supports max 32-bit ints Tim Rentsch <txr@alumni.caltech.edu> - 2013-08-08 14:18 -0700
      Re: 64-bit integers where the implementation supports max 32-bit ints Malcolm McLean <malcolm.mclean5@btinternet.com> - 2013-08-06 05:30 -0700

csiph-web