delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/14/09:42:30

Date: Fri, 14 Mar 1997 09:36:24 -0500 (EST)
From: "art s. kagel IFMX x2697" <kagel AT dg1 DOT bloomberg DOT com>
To: Mike Bales <rbales1 AT flash DOT net>
Cc: djgpp AT delorie DOT com
Subject: Re: Weird problem
In-Reply-To: <33287185.892303@news.flash.net>
Message-Id: <Pine.D-G.3.91.970314092902.4515B-100000@dg1>
Mime-Version: 1.0

DJGPP is a 32 bit compiler so int == long not short.

You can read the two values into two shorts with read() or fread().  
Alternatively you could read the larger record into a buffer and memcpy 
the two 16 bit values to shorts.  

In general, it is good coding practice top explicitely use long and short 
rather than int since short is guaranteed to be 'at least 16 bits' and 
long is guaranteed to be 'at least 32 bits' while int is only defined as 
'the efficient word size' which varies from one machine and compiler to 
another.  I recommend that you only use int when you do not care about 
precision but only about speed.  I reserve int for loop variables and 
array indices when I am confident that the range of values it within the 
precision of any integral datatype that in MIGHT have.

Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com

On Thu, 13 Mar 1997, Mike Bales wrote:

> This may sound stupid because I am new to DJGPP although have been
> using Turbo C++ for years.  Here is some code:
> 
> void main(void)
> {
>    int x;
> 
>    // some code here that puts a value into x
> 
>    printf("X is %d.\n", x);
> }
> 
> This is just an example, not the actual code.  The number it prints as
> variable X is way about the 32767 limit on ints.  (something like a
> million and a half)  Why?
> 
> Also, I am using an Allegro Grabber datafile.  I have a binary file in
> the datafile.  How would I put the first 2 and second 2 bytes of the
> binary file into two int variables?  I have tried a bunch of ways but
> maybe I am doing something wrong with the pointers.  I am not too
> familiar with PM programming...
> 
> Please help.
> 
> Mike
> 

- Raw text -


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