Gestalt

Gestalt is the name of a system call introduced in System 6.0.4 in 1989 to allow applications to dynamically query what capabilities were present in the running system configuration.

By this time, the pace of Macintosh development had produced such a proliferation of hardware configurations and hardware and software add-ons from Apple and third parties that a simple version check was no longer enough to determine the features of the system. Instead, Gestalt maintains a dynamically-extensible table of OSType selector codes.

For instance, instead of checking the system version to deduce what version of the Sound Manager might be present, there is a separate Gestalt selector for directly querying the capabilities of the Sound Manager. Thus, it could be made possible for an application dependent on capabilities introduced in a newer Sound Manager to run on an older system which had the updated Sound Manager installed as an add-on, as well as on a newer system which had the new Sound Manager built-in. And of course the Sound Manager add-on could also query this Gestalt selector first to decide whether there was any point in installing itself into the current system.

The value returned by querying a selector code is 32 bits whose meaning depends on the selector. Some selectors define this as a version code, while others use it as a bit mask of available capabilities. Some subsystems define both types of selectors, allowing querying of both the version number and the capabilities. Some even use a Gestalt selector to pass the address of a shared block of data, or even the address of code that could be called. Since the piece of code that installed a Gestalt selector could either install a simple static value or a callback that Gestalt would invoke every time somebody queried the selector, it was possible for the value returned to vary dynamically from call to call, to reflect information about the current state of the subsystem.

Sources and References

 * Wikipedia: Gestalt (Mac OS)