delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/01/16:01:08

Date: Thu, 1 May 1997 12:40:25 -0700 (PDT)
From: "Jon A. Cruz" <jonc AT twinsun DOT com>
To: Tom Grandgent <tgrand AT canvaslink DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: ints vs. shorts
In-Reply-To: <33687406.4378@canvaslink.com>
Message-ID: <Pine.SOL.3.96.970501123709.4974B-100000@tattoo.twinsun.com>
MIME-Version: 1.0


On Thu, 1 May 1997, Tom Grandgent wrote:

> Jon A. Cruz wrote:
> > 
> > Sorry for this, but you just hit a little pet-peeve of mine.
> > 
> > >From your context, I believe that you should really be saying longs vs.
> > shorts
> > 
> > Coming from 16-bit, you should realize the difference.
> > 
> > int != short
> > int != long
> 
> Yes, I have known this since I made the switch to DJGPP.  However,
> in a 16-bit environment, int did = short, which is why I never used
> short.
> So now int = long, instead of short.  So my question was, do I put
> short all over the place where I used to use int, or should I keep
> using int for most things because of performance issues?
> 
> > int == is whatever the compiler determines is most efficient for the
> > processor.
> 
> Ok, that makes sense.
> 
> > int may be same size as long
> > int may be same size as short
> > short may be same size as long
> > short may not be smaller than long.
> 
> Interesting..  Didn't know short could = long.. :)  But how can
> short not be smaller than long?  Under DJGPP, short is 16 bits and
> long is 32 bits.  Correct?

Oops. Sorry. Got those two switched. Short may not be longer than long.


> 
> > Never read or write ints from your program to files, network, etc.
> > Use short or long.
> 
> Ok, this is the answer to the question I was trying to ask.
> So, on the PC, short is always 16 bits and long is always 32 bits?

Yes. As far as C on Intel processors goes.

> That's what it seems like to me.  So you're saying to use short
> and long for I/O purposes but use int for internal things..
> 
> For example, I have a structure that contains the information
> for a ship in my game.  Coordinates, health, fuel, all kinds of
> things like that.  I am trying to determine whether it would
> be better to use ints or shorts for these sorts of things, as
> well as others.
> 

Use short when you need 16-bit. Use long when you need 32-bit. Use int
when it does not matter.
I'd use ints in your structures, but never read and write your structures
directly (i.e. no write( fh, &structure, sizeof(structure) ) )


> Thanks,
> 
> 	Tom Grandgent
> 	tgrand AT canvaslink DOT com
> 	Canvas Link, Inc.
> 

- Raw text -


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