home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!caen!batcomputer!ghost.dsi.unimi.it!univ-lyon1.fr!frmop11!psuvm!rvk
- Organization: Penn State University
- Date: Mon, 4 Jan 1993 05:13:58 EST
- From: <RVK@psuvm.psu.edu>
- Message-ID: <93004.051358RVK@psuvm.psu.edu>
- Newsgroups: comp.lang.c
- Subject: Followup on size of executables.
- Lines: 61
-
- Thanks to everyone who replied to my earlier posting. I
- feel, however, that I still need some more clarification.
- I was asked what do I mean by a "huge" executable. The
- phrase is perhaps inaccurate. I used it only in relative
- terms, as illustrated by the example below.
-
- Consider the Hello, World example in assembly (for intel 486):
-
- .MODEL small
- .STACK 100h
- .DATA
- CR EQU 13
- LF EQU 10
- EOS EQU '$'
- HelloMessage DB 'Hello, World',CR,LF,EOS
- ExitCode DB 0
- .CODE
- start:
- mov ax,@data
- mov ds,ax ;set DS to point to the data segment
- mov ah,9 ;DOS print string function
- mov dx,OFFSET HelloMessage ;point to 'Hello World'
- int 21h ;display 'Hello, World'
- mov ah,4ch ;DOS terminate program function
- mov al,[ExitCode] ; Exit Code
- int 21h ;terminate the program
- END start
-
-
- and consider the corresponding C fragment:
-
- #include <stdio.h>
- int main() { printf("Hello, World\n"); return 0;}
-
- When compiled with MASM 6.0 the hello.asm generated an
- executable of size 548 bytes, whereas when compiled with
- Microsoft C 7.0 the hello.c generated an executable of
- size 6762 bytes. I agree that the executable generated
- by the C fragment is not large, yet when compared to that
- generated by the assembly code, it is more than 10 times
- larger. It is to this difference that I was refering to.
-
- This brings us to another question: Who cares for a few K's
- more or less?
-
- Well, one answer is that suppose I am writing a TSR for a DOS
- machine ( I haven't written one yet !) , or for that matter
- any low level utility for DOS. There size of executable is of
- concern. Another answer is that theoretically the concern is
- still valid : why do I have to link with everything that's there
- in stdio.h to produce an executable? Note that to write any
- reasonably complex program in C one would need to include a
- whole lot of other header files too e.g. stdlib.h, string.h ....
- each of which will add to the overhead.
-
- This brings me to my final question: Is there no way other than
- programming in assembly, to produce a really small executable?
- I would like to use C, but I don't know how (if at all possible)
- to do that.
-
-
-