delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/20/02:50:02

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.lang.c,comp.os.msdos.djgpp
Subject: Re: having trouble with long numbers
Date: Tue, 19 Aug 1997 19:07:02 -0700
Organization: Alcyone Systems
Lines: 32
Message-ID: <33FA5146.797547D8@alcyone.com>
References: <01bc9c51$0ceeec80$78ed1fcc AT darkstar> <33F1C728 DOT 2690 AT ici DOT net>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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.

Note that even if you're using an iteration variable that goes from 1 to
(say) 10, you're probably better off using int.  int is more likely to be
speedier than short.

-- 
       Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
   "Love is not love which alters / when it alteration finds."
                                 / William Shakespeare, _Sonnets_, 116

- Raw text -


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