ADC Home > Reference Library > Technical Notes > Legacy Documents > Mac OS 9 & Earlier >

Legacy Documentclose button

Important: This document is part of the Legacy section of the ADC Reference Library. This information should not be used for new development.

Current information on this Reference Library topic can be found here:

Pascal Routines Passed by Pointer

CONTENTS

[Jul 01 1985]






Introduction

Routines passed by pointer are used in many places in conjunction with Macintosh system routines. For example, filter procedures for modal dialogs are passed by pointer, as are controls' action procedures (when calling TrackControl), and I/O completion routines.

If you're using MPW Pascal, the syntax is usually

where MyProc is the procedure passed by pointer (using the @ symbol).

Because of the way that MPW Pascal (and some other compilers) construct stack frames, any procedure or function passed by pointer must not have its declaration nested within another procedure or function. If its declaration is nested, the program will crash, probably with an illegal instruction error. The following example demonstrates this:

    PROGRAM CertainDeath;

       PROCEDURE CallDialog;

          VAR
             x : INTEGER;

          FUNCTION MyFilter(theDialog: DialogPtr; VAR theEvent: EventRecord;
                            VAR itemHit: INTEGER): Boolean;
          {note that MyFilter's declaration is nested within CallDialog}

          BEGIN {MyFilter}
            {body of MyFilter}
          END; {MyFilter}

       BEGIN {CallDialog}
          ModalDialog(@MyFilter,itemHit) {<------------ will crash here}
       END; {CallDialog}

    BEGIN {main program}
          CallDialog;

Back to top

References

Macintosh Memory Management: An Introduction

Back to top

Downloadables

Acrobat gif

Acrobat version of this Note (K).

Download



Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.