Article View: comp.std.c
Article #3869Re: Why "long long" doesn't work.
From: FFarance
Date: Sat, 26 Aug 1995 21:46
Date: Sat, 26 Aug 1995 21:46
76 lines
3332 bytes
3332 bytes
> From: alan@rcp.co.uk (Alan Stokes)
>
> In <41hubq$fu3@newsbf02.news.aol.com> ffarance@aol.com (FFarance)
writes:
> >> From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
>
> >> Simpler and better would be to change the rules for varargs functions
so
> >> that instead of the current inegral promotions the promotion is
always
> >to
> >> the largest integer type. Then one does not even need any modifer.
Also
> >> varargs functions become a lot easier to write as you no longer have
to
> >> worry if the argument is smaller or larger than int.
>
> >But what about implementations that have no largest type, i.e., where
the
> >type is arbitrarily long. This scheme would be impractical.
>
> Implementations with no largest type already cause problems with printf.
The point I was making was that Stephen's suggestion that promotion to
the largest integer would cause problems in many areas. Stephen made this
suggestion with the possibly eliminating the "?" type modified in SBEIR
"printf". Arbitrarily large integers are no problem for an SBEIR
implementation because:
printf("%?d",precof(x),x);
always works. Requiring all implementations to support arbitrarily long
integers without any minimum maxima is a problem because I can't write a
strictly conforming application that works on all implementations.
> 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". To do this in SBEIR, you
would use "precof" for "printf" and temporaries:
fpos_t y;
ptrdiff_t z;
printf("fpos %?d, ptr %?d\n",precof(y),y,precof(z),z);
In fact, if you needed a value to hold a temporary of multiplying an
"fpos_t" by a "ptrdiff_t" (assuming this made sense), you could do:
#define FPOS_BIT (EIR_BIT(precof(fpos_t)))
#define PTRDIFF_BIT (EIR_BIT(precof(ptrdiff_t)))
int atleast:(FPOS_BIT+PTRDIFF_BIT) t;
t = y;
t *= z;
printf("result %?d\n",t);
In summary, "long" isn't guaranteed to be the longest type.
-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:
<41o4n4$m0l@newsbf02.news.aol.com>Path:
arc1-ca.pugleaf.net!newsbf02.news.aol.com!not-for-mailReferences:
<ncfPwAmIBh107h@rcp.co.uk>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: 26 Aug 1995 17:46:12 -0400 Organization: America Online, Inc. (1-800-827-6364) Sender: root@newsbf02.news.aol.com Message-ID: <41o4n4$m0l@newsbf02.news.aol.com> References: <ncfPwAmIBh107h@rcp.co.uk> Reply-To: ffarance@aol.com (FFarance) NNTP-Posting-Host: newsbf02.mail.aol.com