delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/22/15:36:06

Newsgroups: comp.lang.c,comp.os.msdos.djgpp
From: christian DOT bau AT isltd DOT insignia DOT comm (Christian Bau)
Subject: Re: having trouble with long numbers
Message-ID: <christian.bau-2208971615150001@christian-mac.isltd.insignia.com>
Sender: news AT isltd DOT insignia DOT com (Usenet News)
Nntp-Posting-Host: christian-mac.isltd.insignia.com
Organization: Insignia Solutions
References: <01bc9c51$0ceeec80$78ed1fcc AT darkstar> <33F1C728 DOT 2690 AT ici DOT net> <33FA5146 DOT 797547D8 AT alcyone DOT com>
Date: Fri, 22 Aug 1997 15:15:15 GMT
Lines: 32
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <33FA5146 DOT 797547D8 AT alcyone DOT com>, Erik Max Francis
<max AT alcyone DOT com> wrote:

> Alicia Carla Longstreet wrote:
> 
> > Depending on the platform ints can be anywhere from 16 bits on up.  The
> > C Standard only requires that it be able to hold numbers from -32768 to
> > 32767 (signed int) or 0 to 65535 (unsigned int). Your use of int to hold
> > 86,400 is not portable and may not even work on your current platform,
> > this would be true even if you used unsigned int.
> > 
> > long long is also not standard (I only know of 1 platform/OS that
> > supports this, which is why I suspect that your ints won't work on your
> > platform).
> 
> Yes.  Short answer:  short is guaranteed to be at least 16 bits; long is
> guaranteed to be at least 32.  int is guaranteed to be no shorter than a
> short (e.g., at least 16 bits).
> 
> If it doesn't much matter what the variable holds, then use int.  If space
> is critical, then use short (if you want a _really_ small integer type,
> you might consider using char, but there may be some unexpected pitfalls).
> If it must hold at least 32 bits, then use long.

The last one is not quite correct: 

If it must hold at least 17 bits, then use long (because int is not
guaranteed to hold 17 bits). If it must hold 32 bits, long is still ok. If
it must hold 33 bits or more, there is no type that is guaranteed to work.

-- For email responses, please remove the last emm from my address. 
-- For spams, please send them to whereever DOT you DOT want AT but DOT not DOT here

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019