24.11.2014 Views

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

Open Watcom FORTRAN 77 Language Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>FORTRAN</strong> Statements<br />

Example:<br />

DIMENSION C(-5:5)<br />

CHARACTER A, B*10(10), C*20<br />

CHARACTER*7 X, Y, Z*4<br />

The (*) length specification is only allowed for external functions, dummy arguments or symbolic<br />

character constants. If a dummy argument has a length specification of (*), it assumes the length of the<br />

corresponding actual argument. If the actual argument is an array name, the length assumed by the dummy<br />

argument is the length of an array element of the actual array.<br />

Example:<br />

SUBROUTINE OUTCHR( STR )<br />

CHARACTER STR*(*)<br />

PRINT *, STR<br />

END<br />

In this example, STR is a character variable whose length is the length of the actual argument. Thus<br />

OUTCHR can be called with a character entity of any length.<br />

If an external function has a length specification of (*) declared in a function subprogram, the function<br />

name must appear as the name of a function in a FUNCTION or ENTRY statement in the same subprogram.<br />

When the function is called, the function assumes the length specified in the program unit that called it. In<br />

the following example, when F is called its length is assumed to be 10.<br />

Example:<br />

CHARACTER*(10) F<br />

.<br />

.<br />

.<br />

PRINT *, F()<br />

.<br />

.<br />

.<br />

END<br />

CHARACTER*(*) FUNCTION F<br />

F = ’HELLO’<br />

END<br />

The following example is illegal since F does not appear in a FUNCTION or ENTRY statement.<br />

Example:<br />

* Illegal definition of function F.<br />

CHARACTER*(*) F<br />

.<br />

.<br />

.<br />

PRINT *, F()<br />

.<br />

.<br />

.<br />

END<br />

The length specified for a character function in the program unit that referenced it must agree with the<br />

length specified in the subprogram that defines the character function. Note that there is always agreement<br />

if the function is defined to have a length specification of (*).<br />

CHARACTER Statement 27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!