From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: Help with errors Date: Wed, 09 Jul 1997 19:35:32 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 51 Message-ID: <33C3E804.6526@cs.com> References: <33c206fc DOT 8853443 AT netnews DOT worldnet DOT att DOT net> <33C2789C DOT 5887 AT emu DOT com> <33c2ba55 DOT 6066342 AT netnews DOT worldnet DOT att DOT net> <33C2D54C DOT 2D26 AT cornell DOT edu> <33c316f1 DOT 6303003 AT netnews DOT worldnet DOT att DOT net> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp108.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Eric Liao wrote: > > Hmm? 32 bit ints are different? That might be the problem. > I used GDB and got an 8 digit or so number, and I was wondering how > that could fit in an int. I always thought an int was 2 bytes on any > compiler. Is a char still one byte? What are the other types? Maybe > I should go look them up. Thanks for the help. ANSI defines int as the native word size of the compiler, and rules that sizeof(short) <= sizeof(int) <= sizeof(long). It says that short must be at least 16 bits and long must be at least 32 bits. It allows the implementation to define the actual size of these types. Every Unix system uses 32-bit integers; 16-bit ints are a DOS peculiarity that DJGPP fortunately does not share. ;) If you write a program that depends on having 16 or 32 bit numbers, you should use short and long explicitly. ANSI defines char as the size needed to store one character in the host operating system, with a minimum size of one byte. Again, that's not really specific, but you can assume it's one byte on any rational system. If you want to know the sizes of all the data types, just use a program like this: /* sizes.c */ #include int main( void ) { printf( "Type sizes for this compiler:\n" " char = %ld short = %ld\n" " int = %ld long = %ld\n" " float = %ld double = %ld\n" " long double = %ld char * = %ld\n", sizeof(char), sizeof(short), sizeof(int), sizeof(long), sizeof(float), sizeof(double), sizeof(long double), sizeof(char *) ); return 0; } Compile this on each compiler you use and run it to see the type sizes. -- --------------------------------------------------------------------- | John M. Aldrich |"Men rarely (if ever) manage to dream | | aka Fighteer I |up a god superior to themselves. Most | | mailto:fighteer AT cs DOT com |gods have the manners and morals of a | | http://www.cs.com/fighteer |spoiled child." - Lazarus Long | ---------------------------------------------------------------------