[comp.sys.mac.programmer] Toolmaker's tip for MPW.

earleh@eleazar.dartmouth.edu (Earle R. Horton) (05/24/88)

When linking MPW tools, use of stubs.c (C) or stubs.a (Pascal) can
lead to substantial reductions in code size of the linked tool.  These
files are on the compiler distribution disks, in the example program
folders.  They provide dummy functions for routines which are used by
applications, but never by tools.  It is helpful to compile the stubs
sources and place the .o files in the appropriate library folder.  The
linker doesn't like the duplicate names, so you have to use the -w
flag when linking to prevent your worksheet from filling up with error
messages.  Link the stubs file before any library files used by the
tool.  Read '\' as 'option-d' in the following link example:

# Link C object files into an MPW Tool using stubs.c.o
Link	-w -b -c 'MPS ' -t MPST \
		"{CLibraries}"stubs.c.o \
		"{CLibraries}"CRuntime.o \
		"{CLibraries}"StdCLib.o \
		"{CLibraries}"CSANELib.o \
		"{CLibraries}"CInterface.o \
		"{Libraries}"Interface.o \
		{YOUR_OBJECT_FILES} -o {YOUR_TOOL_NAME}

I am prompted to make this posting because I have received MPW
Makefiles which indicate the author either didn't look closely at the
example Makefile provided for a Tool, or forgot what he saw there.
ToolMaker's tip #2: read example programs!

*********************************************************************
*Earle R. Horton, H.B. 8000, Dartmouth College, Hanover, NH 03755   *
*********************************************************************

dan@Apple.COM (Dan Allen) (05/27/88)

Watch out for one GOTCHA, however.  The stubs file as it ships with MPW
also stubs out the routines that print floating point numbers.  If you
do a printf with a floating point number nothing will complain but your
answer will be entirely wrong!

A typical misuse of this stubs file came for me when I wrote a simple
tool that did no floating point.  Then I wanted to time the benchmark
with TickCount and print the result rounded to tenths of a second.  The
answers came out all wrong.

WORKAROUND: delete the last two lines of the file which are:

ecvt() {}
fcvt() {}

and then your printf of floating point numbers will work properly and
you will still save a bunch of space.

Dan Allen
Software Explorer
Apple Computer