[NTLUG:Discuss] OT C question

Eric Schnoebelen eric at cirr.com
Sat Feb 18 17:35:33 CST 2006


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




More information about the Discuss mailing list