[NTLUG:Discuss] OT C question

Tom Hayden tom.hayden.iii at mail.airmail.net
Sat Feb 18 21:32:08 CST 2006


O.K. To make this really messy. The ANSI C specification says a SHORT 
int can be no longer than 16 bits. A LONG int must be at least 32 bits. 
A "STANDARD" int must be at least as long as a SHORT int and no longer 
than a LONG int. Thus, the length of an int is not truly defined. It is 
permissible to write a C compiler with a SHORT int of 16 bits, a LONG 
int of 32 bits and a STANDARD int of 24 bits!! Even worse, on a 64 bit 
machine, you could have a LONG int of 64 bits and a STANDARD int anyhere 
from 16 bits to 64 bits, including something truly odd like a STANDARD 
int 43 bits long!!!! Admittedly, neither of these scenarios makes much 
sense, but the specification does allow them.

Eric Schnoebelen wrote:
> steve writes:
> - Greg Edwards wrote:
> - > OBTW, type size is determined by compiler not processor.
> - 
> - This is definitely true - and not just in theory.
> - 
> - Back in the days of Z80's and CP/M, we had two C compilers for
> - the Z80 at work.  One used 16 bit 'int' and the other had
> - 32 bit 'int' - on the same CPU and using the same operating
> - system.
> 
> 	Unusual to say the least.. While I don't have my copy of
> the C89 standard handy (yes, I know it's been updated by C99,
> but the last time I was seriously  playing language lawyer, C89
> was it.. :) according to K&R 2nd Ed;
> 
> 	"int -- an integer, typically reflecting the natural
> 		size of integers on the host machine"
> 
> 	I would bet that the second compiler was developed to
> support a non-natural wordsize  to counter-act the "all the
> world's a VAX" mentality of C in the early to mid 80's.. (later
> replaced by "all the world's a SUN", and more recently by "all
> the world's Linux on ia32")
> 
> 	Most every OS with a C compiler I've experienced in the 20
> years has provided an "int" of the natural word size.  During the
> early days of 64 bit computing, many platforms had two "natrual
> word sizes"  One 32, and one 64 bits wide. Other 64 bit OS compilers
> defaulted to a 32 bit integer, long, and even pointers to try and
> allow code with wordsize assumptions to continue to work without
> major breakage.
> 
> - We had C code from other computers that REQUIRED 32 bit int's,
> - yet for the more performance-critical parts of our system,
> - 16 bit int's were 10x faster...so we compiled some code with
> - one compiler and some with the other.
> 
> 	The 10x performace degradation would be due to the
> "non-natural" word size being used on the Z80...  It takes a lot
> to emulate the larger word size..  
> 
> - If you suspect that this was a recepie for disaster - then
> - you are entirely correct!
> 
> 	Oh, I can certainly imagine.. The calling conventions
> had to be different, leading to all sorts of problems making
> calls between the different code formats.
> 
> 	Ouch!
> 
> --
> Eric Schnoebelen		eric at cirr.com		http://www.cirr.com
>     "I am sorry to say that at the moment I am so busy as to be convinced
>     that life has no meaning what so ever" -- Bertrand Russell, June 1931
> 
> _______________________________________________
> https://ntlug.org/mailman/listinfo/discuss
> 
> 


-- 
Tom Hayden III

Coherent solutions for chaotic situations

tom.hayden.iii at mail.airmail.net
214-435-4174

2636 Verandah Ln.
Apartment 1431
Arlington Texas, 76006





More information about the Discuss mailing list