[M3devel] function pointers and comparison to nil? mis-typed function pointers?

Mika Nystrom mika at async.caltech.edu
Sun Jun 1 20:57:56 CEST 2008


Jay writes:
>--_c746a382-25b6-4547-9df2-927b317b6eab_
>Content-Type: text/plain; charset="iso-8859-1"
>Content-Transfer-Encoding: quoted-printable
>
> > In Modula-3, you can pass any procedure but only assign a top-level proc=
>edure. > This precludes dangling environments in yet another way, that is m=
>ore liberal > than either Pascal or Modula-2,, but requires a runtime check=
> on procedure
>I don't understand "can only assign a top-level procedure".
>My understanding is that Modula-3 does allow the "unsafe" option -- take th=
>e address of a nested function, pass it off to some code, that stores it in=
> a global, and call it later. But of course, "Modula-3 does allow the unsaf=
>e option" does not compute. I need to read up and experiment.
>=20
>Maybe there is a runtime check whenever I assign a function pointer to eith=
>er a global or to a field in non-local record, that it isn't a closure?
>That makes a fair amount of sense though hard to not make the check overly =
>strict I think.
>=20

Jay, surely you remember that:

"A procedure is either NIL or a triple consisting of:

* the body, which is a statement,

* the signature, ...

* the environment, which is the scope with respect to which variable
names in the body will be interpreted.

A top-level procedure is a procedure declared in the outermost
scope of a module.  Any other procedure is a local procedure.
A local procedure can be passed as a parameter but not assigned,
since in a stack implementation a local procedure becomes invalid
when the frame for the procedure containing it is popped.

...
"

The "since in a stack implementation..." clause seems superfluous
to me, but I suppose it might be helpful for those who simply must
think in terms of a specific implementation.







More information about the M3devel mailing list