Thanks for the code, Ed and Ed.  Indeed, don't try this at home.  They're
doing basic macro expansion, which we do with pre-processors all the time,
but it's just not portable in app code.  The issue is that some compilers
will evaluate the expression of an EQUATE, then embed the result into the
object code.  Other compilers, like Unidata here, will do a universal
replacement on the source _before_ compilation.  (I'm sure it's a little
more intelligent.)  All occurences of the expression are then parsed by the
compiler, and assuming the resulting code compiles, all expressions are
re-evaluated every time they're encountered.

The only reason I'm interested in this discussion is that I have a client
facing the same issue with a port from Universe.  They actually did use
reserved words in their EQUATES, where Universe did not do this sort of
replacement, and the target environment behaves like Unidata, causing some
code (not an awful amount) to fail compilation.  Another lesson here -
don't use words that even look like they should be reserved as variables.

On a scale of 1-10: Kewlness factor 3, Annoyance 5.  Aint worth it.
T

Ed Burwell wrote:
> It won't compile the FOO program.
> I've also gotten a user-written function to compile and run
> 0006: EQU TEF.SUB.TOT  TO TEMP(TEF.PARTS,TEF.TAX,TEF.SHIPPING)
> 0008: DEFFUN TEMP(F1,F2,F3)
> 0010: TEF.PARTS    = 100
> 0011: TEF.TAX      = 10
> 0012: TEF.SHIPPING = 20
> 0014: PRINT TEF.SUB.TOT    ; * PRINT 130
> 0015: END
> I even played around with the SADD function in an EQUATE. 

Ed Clark wrote:
> You can come up with some bizzare and totally unportable code in
> unidata using equates:
> EQU READNEXT TO 12345
> ID='2R'
> LOOP WHILE READNEXT ID DO
...
> On universe, this compiles, but the equate processor doesn't replace
> the READNEXT, so it would exit the loop immediately.
> 
> This innocent definition of an ascii table compiles and works on
> universe but won't on unidata:
> EQU NUL TO CHAR(0)
> EQU SOH TO CHAR(1)
> EQU STX TO CHAR(2)
> ...
> EQU DEL TO CHAR(127)
> A='1':@AM:'2'
> DEL A<1>
> CRT A
-------
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/

Reply via email to