Article View: comp.std.c
Article #3882Re: Why "long long" doesn't work.
From: FFarance
Date: Mon, 28 Aug 1995 13:43
Date: Mon, 28 Aug 1995 13:43
50 lines
2656 bytes
2656 bytes
From: thads@csn.net (Thad Smith)
> In article <41o4n4$m0l@newsbf02.news.aol.com>,
> ffarance@aol.com (FFarance) wrote:
>
> >> At present long is known to be the largest signed type, so I can
> >> safely do the following:
> >>
> >> ptrdiff_t x = 0;
> >> printf("%ld", (long) x);
> >>
> >> (where ptrdiff_t can be replaced by any typedef which I know to be
> >signed &
> >> integral but don't know the exact type of). This is a very useful
> idiom,
> >> and this cannot be done at all if there is no largest type.
> >
> > Unfortunately, this idiom isn't portable. There is no guarantee
> > that "ptrdiff_t" will fit in a "long", e.g., systems with 48-bit
> > pointers and 32-bit "long" (some memory models in OS/2). Another
> > example is "fpos_t": it may be larger than "long".
>
> In Standard C ptrdiff_t must be a signed integral type defined in
> Standard C (see enumeration of signed integer types in ANSI 3.1.2.5).
> There is no integral type in C larger than long int, hence casting to
> long should be portable. Note, however, that overflow is possible as
> a result of subtracting pointers. fpos_t can certainly be larger than
> a long -- it isn't even restricted to be a scalar type, let alone
> arithmetic or integral, but might be a structure.
Boy my head must have been screwed on wrong that day (-:! You're right
on both points. The first point on "long" being the longest type is
true for strictly conforming applications (which was your point). I was
thinking of the extended integer work were I think many assume "long"
won't
remain the longest type in C9X. I'll include your example in the SBEIR
proposal as an issue.
In my multiplication example, I was assuming that "fpos_t" was an
integral type for that implementation. The point was to generate a
temporary with enough precision - I'll use a better example.
Thanx for pointing out my mistakes.
-FF
-------------------------------------------------------------------
(``I only use AOL for reading netnews.'')
Frank Farance, Farance Inc.
E-mail: frank@farance.com, Telephone: +1 212 486 4700
ISO JTC1/SC22/WG14 & ANSI X3J11 (C Programming Language) Project Editor
Technical Details
Message-ID:
<41sh6f$ssu@newsbf02.news.aol.com>Path:
arc1-ca.pugleaf.net!newsbf02.news.aol.com!not-for-mailReferences:
<+HCQwQ9ythna084yn@csn.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsbf02.news.aol.com!not-for-mail From: ffarance@aol.com (FFarance) Newsgroups: comp.std.c Subject: Re: Why "long long" doesn't work. Date: 28 Aug 1995 09:43:43 -0400 Organization: America Online, Inc. (1-800-827-6364) Sender: root@newsbf02.news.aol.com Message-ID: <41sh6f$ssu@newsbf02.news.aol.com> References: <+HCQwQ9ythna084yn@csn.net> Reply-To: ffarance@aol.com (FFarance) NNTP-Posting-Host: newsbf02.mail.aol.com