Path: utzoo!attcan!uunet!lll-winken!csd4.milw.wisc.edu!uxc!uxc.cso.uiuc.edu!m.cs.uiuc.edu!brown From: brown@m.cs.uiuc.edu Newsgroups: comp.sys.ibm.pc Subject: Re: Looking for a decent C compiler Message-ID: <8000050@m.cs.uiuc.edu> Date: 8 Jun 89 03:01:00 GMT References: <1440@bucket.UUCP> Lines: 47 Nf-ID: #R:bucket.UUCP:1440:m.cs.uiuc.edu:8000050:000:2252 Nf-From: m.cs.uiuc.edu!brown Jun 7 22:01:00 1989 /* Written 5:09 pm Jun 6, 1989 by phil@ux1.cso.uiuc.edu in m.cs.uiuc.edu:comp.sys.ibm.pc */ What's wrong with a C compiler than knows if an array is larger than a 64K segment that it just simply has to generate code that can calculate the correct segment address and displacement each time it needs to access an array location? It's not THAT hard to do, but sure, it will slow down the program. What would be nice is a compiler than CAN do this if the array is declared obviously larger than 64K. Also, pointer arithmetic may need this code, and this should be specifiable as a compile option as well. So, can any 8086 C compiler DO THAT? --Phil howard-- /* End of text from m.cs.uiuc.edu:comp.sys.ibm.pc */ Both the Lattice C and the Microsoft C (and doubtlessly many others) can do (most) of this. In Lattice C, all pointers in large model (L) or large data model (D) are managed by function calls which compute segment and offset locations whenever a pointer is referenced. Since this happens for all pointer references without regard to the size of the object that they reference, performance is low for all pointer operations. Microsoft C takes a different approach: by default, pointers are manipulated by operations on the offset only (the object is presumed to be less than 64K in size whether it is "near" (referenced by a 16-bit pointer for an object in the default data segment) or "far" (referenced by a 32-bit pointer for an object in an additional data segment)). This may be overridden by including the "huge" keyword in a declaration. When a "huge" pointer is referenced, both the segment and offset are calculated. As far as having arrays larger than 64K automatically detected and supported, there are some problems. Since auto variables typically are on the stack, and the stack is in a segment which can be no larger than 64K, then auto arrays larger than 64K present some real obstacles. I'm not aware of how either of the above compilers handles this case (I believe that it generates a compile-time error in both). Typically such arrays are allocated from the heap (via malloc). William Brown brown@cs.uiuc.edu University of Illinois at Urbana-Champaign