delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/14/02:29:02

From: Ray Ratelis <ray AT shoreland DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Weird problem
Date: Thu, 13 Mar 1997 16:19:47 -0600
Organization: Shoreland, Inc.
Lines: 40
Message-ID: <33287D83.63AD@shoreland.com>
References: <33287185 DOT 892303 AT news DOT flash DOT net>
NNTP-Posting-Host: zeus.shoreland.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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

It is because in Turbo C++, ints are 2 bytes in size. (int = 16bit,
short int = 8bit(?))
In PM, and any other 32bit OS, ints are 4 bytes in size. (int = 32bit =
long int, short int = 16bit)

to fix it, you should try to use a short int for the binary file reader.
and as for the 32767 limit, that's a signed 16bit max. For 32 bits, the
max is 2147483648 for signed ints.

Hope this helps.

- Ray Ratelis

- Raw text -


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