本文共 2001 字,大约阅读时间需要 6 分钟。
Variables in IDL COMMON blocks do not actually have names. Rather, IDL represents COMMON blocks internally as an array of variables, and these variables are referenced by their positional index. Hence, the first variable is at position 0, the second at position 1, and so forth. When you specify a COMMON block declaration in an IDL routine, you specify names to be used for these variables within the scope of that routine.
The common block definition statement creates a common block with the designated name and places the variables whose names follow into that block. Variables defined in a common block can be referenced by any program unit that declares that common block. The general form of the COMMON block definition statement is as follows:
Block_Name, Variable1, Variable2, ..., Variablen
The number of variables appearing in the common block cannot change after the common block has been defined. The first program unit (main program, function, or procedure) to define the common block sets the number of included variables; other program units can reference the common block with any number of variables up to the number originally specified. Different program units can give the variables different names, as shown in the example below.
The two procedures in the following example show how variables defined in common blocks are shared.
ADD, A
SHARE1, X, Y, Z, Q, R
A = X + Y + Z + Q + R
, X, Y, Z, Q, R, A
SUB, T
SHARE1, A, B, C, D
T = A - B - C - D
, A, B, C, D, T
The variables X, Y, Z, and Q in the procedure ADD are the same as the variables A, B, C, and D, respectively, in procedure SUB. The variable R in ADD is not used in SUB. If the procedure SUB were to be compiled before the procedure ADD, an error would occur when the COMMON definition in ADD was compiled. This is because SUB has already declared the size of the COMMON block, SHARE1, which cannot be extended.
转载地址:http://wxiqb.baihongyu.com/