Apr 89 Letters
Volume Number: 5
Issue Number: 4
Column Tag: Letters
Letters
By David E. Smith, Editor & Publisher, MacTutor
Aztec C
Rich Heady
San Diego, CA
Aztec C is all I was told it would be, and I’m already pleased with the results. It
is particularly gratifying to have access to “intermediate code” again after being
locked inside Lightspeed C’s projects for the past 18 months, and more gratifying still
to find the assembly code already optimized to the point where I may not need to go
through cleaning up the little stupidities. There is nothing wrong with Lightspeed C; in
fact, it remains a superior prototyping environment. But at the point where I began to
look beyond the prototype to a shippable product, it was a relief to find Aztec C ready to
finish the job. Aztec C might carve a bigger niche in the Macintosh world by appealing
to the “1 Meg programmer” who wants to produce polished code without larding on
RAM and without wading into the complexity of MPW.
Typos upon Typos
Ajay Nath
Oakland Gardens, NY
I’ve been writing a driver for my plotter, and I’ve been looking at the code you
presented in MacTutor, Volume 3, Number 11 and 12. I’ve caught some errors in the
code you presented on page 57 (#12). The code in the procedure DrvrStorage():
;1
asm {
MOVEQ #8, D0
MOVE.L UTableBase, A0
ADDA DO, A0
MOVE.L (A0), OutDctlEntry
}
I wrote to you about this error before, but you printed my correction
incorrectly! (You did print my explanation of why the author’s code was wrong
correctly.) [Sorry, we will double our efforts. -ed]
On page 59 in the procedure MyPrDlgMain() at the end of this proc a pointer is
freed and then accessed as follows:
/* 2 */
free(+p); /*ptr is being freed by a subroutine */
if (tp->fDolt) (void) MyPrValidate(hPrint);
/*we accessed the ptr we freed */
return (tp->fDolt); /* you did it again! */
if (tp->fDolt) is true the subroutine “MyPrValidate” will be called, and it calls traps
like GetResource and LoadResource which will move memory so that doing a subsequent
“return(tp->fDolt)” may be pointing to garbage.
One way to fix this is to do the following:
/* 3 */
{ Boolean theResult;
/* a local variable to hold function result */
theResult = tp->fDolt; /*save the value of fDolt */
free (tp);
if (theResult) (void) MyPrValidate(hPrint);
return (theResult);
}
on page 58 in the procedure “MyPrintDefault(hPrint)” one of the lines:
**hPrint = **theDefault;
the same line appears on page 59 near the end of the procedure MyPrValidate(hPrint)
What the author is trying to do is to fill in the fields of the data structure that
hPrint points to, what he actually does is mess up the hPrint handle. What he should
do is something like this:
/* 4 */
BlockMove(*theDefault, *hPrint, sizeof(TPrint));
and probably:
/* 5 */
ReleaseResource(theDefault);
/* unload resource now that we’re done */
It is a good article which provides information on how to write printer drivers,
but some of the code is incorrect.
In MacTutor, Vol. 4, #11, the code presented by Donald Koscheka to do a string
comparison uses the “DBRA” instruction incorrectly. When you loop using “DBRA”
you use the word (16 bits) in the register you use as a loop counter; Mr. Koscheka
uses register D1 as his loop counter and sets its value by doing:
MOVE.B (A))+, D1 ; get length of string 1
This sets the lower 8 bits of D1, NOT the lower word. The correct way to load the
value of the loop counter in this case is to:
;6
MoveQ #0, D0 ; set D0 = 0;
Move.B (A0)+, D0 ; D0 = string length
Also when using the “DBRA” instruction, the register must actually have the
loop count -1 in it, i.e. if you want to loop 10 times, put 9 in the register. Mr.
Koscheka doesn’t do this. I realize that he was showing a code fragment, but the
purpose of his article was to show how to use assembly language and allowing such
errors to slip in does readers a disservice.
FORTRAN Math Libraries
Michael M. J. Tracy
Pittstown, NJ
I am writing in response to Tatsuhito Koya’s request (Feb 1989, Vol. 5 No. 2)
for information on FORTRAN math libraries that will run on the Mac. There is an
excellent book out called ‘Numerical Recipes: The Art of Scientific Computing’ by