klg0582@uxa.cso.uiuc.edu (09/19/90)
I used to write programs using Turbo Pascal, but recently I have changed to Turbo C. One thing I don't like for Turbo C is that the executable code for the program of same purpose is larger in C than in pascal. Is this generally true or is there a way to avoid this? Also, if I added in an irrelevent function to a program (the other function won't have any link to this added-in function at all), the code becomes larger accordingly. Could anyone tell me why? thanks in advance, Ken H. Lin lin@uiwpl.ece.uiuc.edu
spolsky-joel@cs.yale.edu (Joel Spolsky) (09/20/90)
In article <139400009@uxa.cso.uiuc.edu> klg0582@uxa.cso.uiuc.edu writes: >One thing I don't like for Turbo C is that the >executable code for the program of same purpose is larger in C than in >pascal. Is this generally true or is there a way to avoid this? This may be true for trivially small programs but the difference is probably insignificant for large programs. One way to reduce the size of Turbo C programs is to use Pascal calling conventions instead of C. That helps a bit. Also avoid big general purpose functions like [c]printf if fputs and itoa will do the job. >Also, if I added in an irrelevent function to a program (the other >function won't have any link to this added-in function at all), the >code becomes larger accordingly. Could anyone tell me why? I'm not sure if I understand your question, but the answer is probably that the Turbo linker is not very bright; it goes for speed over brains. If you have a module with 2 functions in it and only reference one, the entire module is linked in. An argument for splitting up your libraries / OBJ files as much as possible. If you are really hurting for space get the latest version of Turbo C and use VROOM, or buy an expensive linker. Joel Spolsky spolsky@cs.yale.edu Silence = Death
sidney@saturn.ucsc.edu (Sidney Markowitz ) (09/20/90)
In article <139400009@uxa.cso.uiuc.edu> klg0582@uxa.cso.uiuc.edu writes: >executable code for the program of same purpose is larger in C than in >pascal. Is this generally true or is there a way to avoid this? > >Also, if I added in an irrelevent function to a program (the other >function won't have any link to this added-in function at all), the >code becomes larger accordingly. Could anyone tell me why? The size difference is mostly due to the portions of the RTL getting linked in. Look at a linker map to get an idea as to what is taking up space. In particular, using printf will bring in a lot of code that you may be able to avoid by using more low-level output functions. Turbo Pascal has a "smart linker" which will ignore library routines if they are not referenced in your program. Unfortunately, this is made possible by the special nonstandard format of TPUs, and Turbo C and Turbo C++, which use the Microsoft OBJ format cannot do that so easily. -- sidney markowitz <sidney@saturn.ucsc.edu>
ucbked@athena.berkeley.edu (Earl H. Kinmonth) (09/20/90)
In article <26252@cs.yale.edu> spolsky-joel@cs.yale.edu (Joel Spolsky) writes: >In article <139400009@uxa.cso.uiuc.edu> klg0582@uxa.cso.uiuc.edu writes: >>One thing I don't like for Turbo C is that the >>executable code for the program of same purpose is larger in C than in >>pascal. Is this generally true or is there a way to avoid this? Even with all of the debug options turned off, Turbo C produces rather bloated *.exe files. The MKS Toolkit includes an analog to **IX strip that will generally reduce *.exe files by 25-40%. Essentially this does what one of the options in the MSC linker does, if I remember correctly. Assuming (I don't have time to check) the processing is similar to **IX, tlink is probably leaving the symbol table attached to the executable, although this has no subsequent use (except with standalone debuggers). One should also check for floating point library inclusion. A single floating point calculation, especially with emulation, will add substantial overhead. Moreover, simple floating point calculations can often be replaced by integer operations.
dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (09/21/90)
In article <26252@cs.yale.edu> spolsky-joel@cs.yale.edu (Joel Spolsky) writes: >In article <139400009@uxa.cso.uiuc.edu> klg0582@uxa.cso.uiuc.edu writes: >>One thing I don't like for Turbo C is that the >>executable code for the program of same purpose is larger in C than in >>pascal. Is this generally true or is there a way to avoid this? > >This may be true for trivially small programs but the difference >is probably insignificant for large programs. That makes sense if the difference is all in the linking (TP's linker is better at dead code/dead data removal than TC's), but I've never seen a comparison of the code generation that would convince me whether or not that's true. Have you, or has anyone else? Duncan Murdoch dmurdoch@watstat.waterloo.edu