home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19173 < prev    next >
Encoding:
Text File  |  1993-01-04  |  2.4 KB  |  71 lines

  1. Path: sparky!uunet!cs.utexas.edu!uwm.edu!caen!batcomputer!ghost.dsi.unimi.it!univ-lyon1.fr!frmop11!psuvm!rvk
  2. Organization: Penn State University
  3. Date: Mon, 4 Jan 1993 05:13:58 EST
  4. From: <RVK@psuvm.psu.edu>
  5. Message-ID: <93004.051358RVK@psuvm.psu.edu>
  6. Newsgroups: comp.lang.c
  7. Subject: Followup on size of executables.
  8. Lines: 61
  9.  
  10. Thanks to everyone who replied to my earlier posting. I
  11. feel, however, that I still need some more clarification.
  12. I was asked what do I mean by a "huge" executable. The
  13. phrase is perhaps inaccurate. I used it only in relative
  14. terms, as illustrated by the example below.
  15.  
  16. Consider the Hello, World example in assembly (for intel 486):
  17.  
  18. .MODEL small
  19. .STACK 100h
  20. .DATA
  21. CR EQU 13
  22. LF EQU 10
  23. EOS EQU '$'
  24. HelloMessage DB 'Hello, World',CR,LF,EOS
  25. ExitCode DB 0
  26. .CODE
  27. start:
  28. mov ax,@data
  29. mov ds,ax       ;set DS to point to the data segment
  30. mov ah,9        ;DOS print string function
  31. mov dx,OFFSET HelloMessage ;point to 'Hello World'
  32. int 21h         ;display 'Hello, World'
  33. mov ah,4ch      ;DOS terminate program function
  34. mov al,[ExitCode] ; Exit Code
  35. int 21h         ;terminate the program
  36. END start
  37.  
  38.  
  39. and consider the corresponding C fragment:
  40.  
  41. #include <stdio.h>
  42. int main() { printf("Hello, World\n"); return 0;}
  43.  
  44. When compiled with MASM 6.0 the hello.asm generated an
  45. executable of size 548 bytes, whereas when compiled with
  46. Microsoft C 7.0 the hello.c generated an executable of
  47. size 6762 bytes.  I agree that the executable generated
  48. by the C fragment is not large, yet when compared to that
  49. generated by the assembly code, it is more than 10 times
  50. larger. It is to this difference that I was refering to.
  51.  
  52. This brings us to another question: Who cares for a few K's
  53. more or less?
  54.  
  55. Well, one answer is that suppose I am writing a TSR for a DOS
  56. machine ( I haven't written one yet !) , or for that matter
  57. any low level utility for DOS. There size of executable is of
  58. concern. Another answer is that theoretically the concern is
  59. still valid : why do I have to link with everything that's there
  60. in stdio.h to produce an executable? Note that to write any
  61. reasonably complex program in C one would need to include a
  62. whole lot of other header files too  e.g. stdlib.h, string.h ....
  63. each of which will add to the overhead.
  64.  
  65. This brings me to my final question: Is there no way other than
  66. programming in assembly, to produce a really small executable?
  67. I would like to use C, but I don't know how (if at all possible)
  68. to do that.
  69.  
  70.  
  71.