Implicit declaration

If a name appears in a program and is not explicitly declared, it is implicitly declared. The scope of an implicit declaration is determined as if the name were declared in a DECLARE statement immediately following the PROCEDURE statement of the external procedure in which the name is used.

With the exception of files, entries, and built-in functions, implicit declaration has the same effect as if the name were declared in the outermost procedure. For files and built-in functions, implicit declaration has the same effect as if the names were declared in the logical package outside any procedures.

Note: Using implicit declarations for anything other than built-in functions and the files SYSIN and SYSPRINT is in violation of the 1987 ANSI standard and should be avoided.

Some attributes for a name declared implicitly can be determined from the context in which the name appears. These cases, called contextual declarations, are listed as follows:

  • A name of a built-in function.
  • A name that appears in a CALL statement or the CALL option of INITIAL, or that is followed by an argument list, is given the ENTRY and EXTERNAL attributes.
  • A name that appears in the parameter list of a PROCEDURE or ENTRY statement is given the PARAMETER attribute.
  • A name that appears in a FILE or COPY option, or a name that appears in an ON, SIGNAL, or REVERT statement for a condition that requires a file name, is given the FILE attribute.
  • A name that appears in an ON CONDITION, SIGNAL CONDITION, or REVERT CONDITION statement is given the CONDITION attribute.
  • A name that appears in the BASED attribute, in a SET option, or on the left-hand side of a locator qualification symbol is given the POINTER attribute.
  • A name that appears in an IN option, or in the OFFSET attribute, is given the AREA attribute.

Implicit declarations that are not contextual declarations acquire all attributes by default, as described in Defaults for attributes. Because a contextual declaration cannot exist within the scope of an explicit declaration, it is impossible for the context of a name to add to the attributes established for that name in an explicit declaration.

Examples of contextual declaration

In the following statements, PREQ is given the FILE attribute, and S is given the AREA attribute.

  read file (PREQ) into (Q);

  allocate X in (S);