www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/24/10:58:01

Date: Wed, 24 Sep 1997 16:57:46 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: djgpp AT delorie DOT com
Subject: Re: %d
In-Reply-To: <zhL2pNAk$nJ0Ew0M@foobar.co.uk>
Message-ID: <Pine.SUN.3.91.970924164546.19351C-100000@is>
MIME-Version: 1.0

On Mon, 22 Sep 1997, Paul Shirley wrote:

> >It is true that for some architectures, ints are faster than shorts.  
> >However, when portability is an issue, IMHO, use shorts and don't look 
> >back.
> 
> The net result is for a 2 byte data saving you pay much more in extra 
> code and potentially reduced cache effectiveness.

My advice was for the cases where portability is an issue, not data 
saving.  I do agree that using shorts for the purpose of saving data
is a bad idea.

> gcc will optimise away most of this, even so we are seeing measurable
> speedups from switching shorts->ints in R3000 code.

Can you post some measurements?  How much slower is the code that uses 
shorts.  (Please note that I did advise against using shorts as the index 
in a tight loop, since there portability is usually not an issue at all.)

> The only reasons to use shorts are: saving memory in arrays,interfacing
> to hardware.
> The portability argument is nonsense apart from the rare case where
> extra precision breaks code:

When you do need a short (like for referencing hardware) and you do want 
your code to compile correctly with different compilers, portability
certainly does make sense, at least to me.  How many times did you see 
code posted to this newsgroup where a struct had ints as members, and 
which works with Borland C, but breaks with DJGPP?

- Raw text -


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