home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!usenet.ins.cwru.edu!agate!spool.mu.edu!howland.reston.ans.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!chsun!zurich!gegu
- From: gegu@zurich.spectrospin.ch (Gerry Gucher)
- Newsgroups: comp.lang.c
- Subject: Re: HALLOC and HUGE ptrs in Microsoft C
- Summary: C is portable, implementations are not
- Message-ID: <206@zurich.spectrospin.ch>
- Date: 24 Jan 93 17:21:30 GMT
- References: <1993Jan21.175608.4279@arizona.edu>
- Distribution: world,local
- Organization: Spectrospin AG, Fallanden Switzerland
- Lines: 56
-
- In article <1993Jan21.175608.4279@arizona.edu>, jjr@ace.ece.arizona.edu (Jeffrey J. Rodriguez) writes:
- > On a 486 running DOS, I need to allocate an array that's bigger than 64K,
- > ll it up with data, and write it to a binary file.
- > The MSC 7.0 manual says to use halloc(), which returns a "huge ptr".
- > It also says that huge ptrs cannot be passed as args to library functions.
- > Therefore, I can't pass the array to fwrite()!
-
- I doubt that you interpret the manual correctly.
- Huge pointers are simply far pointers that have their seg:offset
- pair normalized so that the offset is always smaller than 16.
- If a library gets 0x1000:0x0005 it can not tell the difference from a far
- pointer.
-
- > So, how do I write the data? (Do I really have to loop through putchar?)
-
- If anything I would loop over fwrite() to print large binary data.
-
- >
- > This sure seems cumbersome.
- > It also seems that a program written for PC-DOS using halloc and huge
- > ptrs would not run on a Sun running UNIX.
-
- That is right, but it's easy to fix. Just do:
-
- #define huge /* empty */
- #define halloc(x) malloc(x)
-
- > So much for portable C.
-
- C is in fact portable. But due to the braindamaged memory architecture,
- most if not all compiler vendors in the MESS-DOS world chose to implement
- a language that looks like C but isn't C. They invented new
- keywords like "huge, far, ..." etc. which makes their language non standard
- conformant. When they claim ANSI compatibility, they mean the "small" memory
- model only. Fortunately most problems can be solved by defining the problem
- away. Additionally every C implementor can extend the library with more
- functions (e.g. halloc) and using those makes your code non portable. This
- is your problem and has nothing to do with the portability of C.
-
- Back to your question about fwrite(). You can eiter break you fwrite() call
- into a series of fwrites() each writing less than 64 kB at once or you can try
- to make the size of your items larger (say 1k words) and write less items.
- I have never tried this but it might work (even on a PC). Of course you
- must use the "large" memory model library for fwrite(). E.g.
-
- instead : fwrite( buf, 200000, sizeof(int), fp );
- try : fwrite( buf, 2000, 1000*sizeof(int), fp );
-
- I have not tried it but it might work.
- >
- > Jeff Rodriguez
- > rodriguez@ece.arizona.edu
-
- Gerry
-
-
-