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


Groups > comp.lang.c > #62287

Re: determines if it is a signed type

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: determines if it is a signed type
Date 2015-05-19 08:03 -0700
Organization None to speak of
Message-ID <87d21w4njn.fsf@kst-u.example.com> (permalink)
References (4 earlier) <mjcnfm$43l$1@dont-email.me> <87a8x253s1.fsf@kst-u.example.com> <mjdero$674$1@dont-email.me> <87k2w54je5.fsf@kst-u.example.com> <mjdr3q$o1i$1@dont-email.me>

Show all headers | View raw


Richard Heathfield <rjh@cpax.org.uk> writes:
> On 18/05/15 23:21, Keith Thompson wrote:
>
> <snip>
>
>> I did not consider implementations that don't support the current
>> or previous C standard.  Nor did I consider implementations that
>> only support K&R C, or B, or BCPL.
>
> Everyone draws their own line. My line is between K&R C and C90
> (i.e. all ISO C versions), and yours seems to be between C95 and C99
> (i.e. all ISO C versions from C99 onwards). Curious: when C2X is
> released, will you drop support for C99?

Support?  What support?

When I post code here, I usually assume C99 or C11.  I often acknowledge
that support for C99 or later is not universal.  I didn't happen to do
so this time.

Here's a version that's portable to C90, C99, and C11.  It can fail for
a pre-C99 implementation that supports integer types wider than long as
an extension, and that uses such a type for time_t.

#include <stdio.h>
#include <time.h>

#if __STDC_VERSION__ >= 199901L
    #include <inttypes.h>
#else
    typedef unsigned long uintmax_t;
    typedef long intmax_t;
    typedef long signed_max;
    #define PRIdMAX "lu"
    #define PRIuMAX "ld"
#endif

int main(void) {
    time_t now = time(NULL);

    if ((time_t)-1 > 0) {
        /* time_t is unsigned */
        printf("%" PRIuMAX "\n", (uintmax_t)now);
    }
    else if ((time_t)1 / 2 == 0) {
        /* time_t is signed */
        printf("%" PRIdMAX "\n", (intmax_t)now);
    }
    else {
        /* time_t is floating-point */
        printf("%Lf\n", (long double)now);
    }
    return 0;
}

-- 
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 | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:07 -0700
  Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-17 18:12 +0100
    Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 10:34 -0700
      Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:09 -0700
      Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 18:22 +0000
        Re: determines if it is a signed type asetofsymbols@gmail.com - 2015-05-17 11:31 -0700
          Re: determines if it is a signed type Kusalananda <kusalananda@example.com> - 2015-05-17 19:59 +0000
  Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-17 13:12 -0700
  Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:08 -0500
    Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 19:46 -0500
    Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 01:59 +0100
      Re: determines if it is a signed type Morris Dovey <mrdovey@iedu.com> - 2015-05-17 20:10 -0500
      Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:37 -0700
        Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-18 21:15 +0100
          Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:15 -0700
        Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 21:51 +0000
          Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 18:00 -0400
      Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 14:37 +0000
        Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 17:09 +0200
          Re: determines if it is a signed type glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-05-18 18:14 +0000
    Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 06:34 +0100
      Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:43 -0700
        Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 13:56 +0100
          Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 08:00 -0700
            Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 20:35 +0100
              Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-18 23:08 +0200
                Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-18 22:32 +0100
                Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 00:44 +0200
                Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:05 +0100
                Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 01:43 +0200
                Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 01:08 +0100
                Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:33 +0100
                Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:15 -0700
                Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 19:36 +0100
                Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 11:55 -0700
                Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 11:39 +0200
                Re: determines if it is a signed type "Bartc" <bartc@freeuk.com> - 2015-05-19 11:44 +0100
                Re: determines if it is a signed type jacobnavia <jacob@jacob.remcomp.fr> - 2015-05-19 12:11 +0200
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 05:45 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 15:03 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 08:46 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 17:08 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-19 09:52 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-19 20:36 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-20 07:40 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-20 23:12 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-21 13:52 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-21 22:48 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-22 05:50 -0700
                Re: determines if it is a signed type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-22 23:14 +0100
                Re: determines if it is a signed type jadill33@gmail.com - 2015-05-26 14:31 -0700
                Re: determines if it is a signed type Tim Rentsch <txr@alumni.caltech.edu> - 2015-05-22 23:32 -0700
                Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-20 12:26 +0200
                Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 15:28 +0100
                Re: determines if it is a signed type raltbos@xs4all.nl (Richard Bos) - 2015-05-23 10:37 +0000
              Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 15:21 -0700
                Re: determines if it is a signed type Richard Heathfield <rjh@cpax.org.uk> - 2015-05-19 00:04 +0100
                Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:03 -0700
                Re: determines if it is a signed type David Brown <david.brown@hesbynett.no> - 2015-05-19 08:47 +0200
                Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-19 08:07 -0700
          Re: determines if it is a signed type James Kuyper <jameskuyper@verizon.net> - 2015-05-18 11:28 -0400
    Re: determines if it is a signed type Keith Thompson <kst-u@mib.org> - 2015-05-18 00:40 -0700

csiph-web