Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiler SYMBOLIC Variables

Status
Not open for further replies.

BruceAcK

Programmer
Jan 30, 2007
2
US
Do any of the Fortran variants support "symbolic variables"? That is to say, variables used by the compiler at compile time. They are not part of the program but used to direct the compiler. They are called various things: compiler variables, macro variables, symbolic variables.
In S/360 assembler you can state:
ABC EQU 321
This causes the text string "321" to be associated with the label "ABC". So when the assembler sees ABC it replaces it with 321. So saying L 5,ABC loads the contents of location 321 into register 5. Similarly, CL&ABC is the same as saying CL321. (& is the concat symbol)
In Fortran type languages it is nice for specifying sizes of arrays and DO loop limits.
%LET AMAX=100 [this is a SAS construct]
DIMENSION MYARRAY(AMAX)
DO 500 I=1, AMAX
MYARRAY = 0.0
500 CONTINUE
This code would result in allocating a REAL array of 100 elements and then zeroing it out. Any place in the code where I use AMAX by itself or concatenated via the concat symbol the compiler just does the substitution. Very similar to macro generated code.
Hope I didn't talk too much. Anybody familiar with type of symbolic coding?
Bruce.
 
See PARAMETER attribute for named constants.
Code:
INTEGER, PARAMETER:: ABC = 100
 

Thanks ArkM. That is exactly what I was looking for. Somehow I glossed over the PARAMETER statement and thought it meant something else. I have been away from FORTRAN for some time and have gotten used to the way other languages do it. Need to take off the blinders so to speak. FORTRAN has changed quite a bit over the years.
 
I feel the same. PARAMETER was introduced in Fortran 30 years ago in slightly different form.
Good luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top