delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/01/17:30:20

From: "matthew p. conte" <spam AT somebody DOT else>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: int being 2 or 4 bytes long
Date: Sun, 1 Mar 1998 17:17:20 -0500
Organization: little, if any
Lines: 23
Message-ID: <6dcmjj$2ha@dfw-ixnews8.ix.netcom.com>
References: <Chameleon DOT 980301230613 DOT nrotem AT netvision DOT netvision>
Reply-To: "matthew p. conte" <dont AT bother DOT com>
NNTP-Posting-Host: alb-ny8-24.ix.netcom.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Noam Rotem wrote in message ...
>Maybe it's trivial, but why is there a data type which its size
>can be different in different compilers? I refer to 'int'. Why
>can it be 2 or 4 bytes, depending on the implementation? What's
>the logic?

I may be wrong, but I believe the ANSI standard imposes these rules:

 char       1 byte
 short      <= sizeof(int)
 int        <= sizeof(long)
 unsigned   == sizeof(int)
 float      <= sizeof(double)

So you can see that there is a fair degree of latitude in how the size of
the variable types are set.  The sizes are probably based on the size that
the CPU natively handles the fastest, i.e. 32-bit code would have a 4-byte
int.


Matt.


- Raw text -


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