On 19/07/2008, at 9:05 AM, Rory Hewitt wrote:

I just end up with a long list of IF, ELSE, ENDIF stuff, like below

Just a thought - can you indent compilation directives - I know you can with
/COPY, even if the manual doesn't make this clear).

Nope: Compiler gives RNF0257 but it gives me that error for indented / COPY statements too so you might want to verify your statement.

It's still a hassle, but
it might make it clearer to look at

/IF DEFINED(COND1)
/IF DEFINED(COND2)
/DEFINE CONDS1AND2
/ELSE
/DEFINE COND1ONLY
/ENDIF
/ELSE
/IF DEFINED(COND2)
/DEFINE COND2ONLY
/ENDIF
/ENDIF

Like I said: messy. Although since you are setting conditions for the AND case it adds nothing to the basic compiler support. Testing /IF DEFINED(CONDS1AND2) is the same as testing nested conditions directly:
/IF DEFINED(COND1)
/IF DEFINED(COND2)
... do something ...
/ENDIF
/ENDIF

If there are definitions common to both the COND1 and COND2 cases, but not otherwise required, then you have to specify those definitions in at least two places. That's what I'm trying to avoid.

In my case the /DEFINE is done outside my control. A consumer of my include can /DEFINE X and get certain behaviour or /DEFINE Y and get other behaviour but if either X or Y is defined then I want some common behaviour. I'm trying to avoid having to duplicate definitions inside each conditional directive.

Your solution suffers from the same problem as my own: namely that once you've determined the appropriate condition you need to duplicate definitions: For example:

/IF DEFINED(COND1)
/IF DEFINED(X)
D doStuff PR EXTPROC('function4')
/ELSEIF DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function1')
/ENDIF
/ELSEIF DEFINED(COND2)
/IF DEFINED(X)
D doStuff PR EXTPROC('function4')
/ELSEIF DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function2')
/ENDIF
/ELSE
/IF DEFINED(X)
D doStuff PR EXTPROC('function4')
/ELSEIF DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function3')
/ENDIF
/ENDIF

Notice that for X and Y the function doStuff is mapped to the same external function therefore I have to code it in each conditional directive. What I want is:

/IF DEFINED(COND1)
/IF DEFINED(X)
/OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function1')
/ENDIF
/ELSEIF DEFINED(COND2)
/IF DEFINED(X)
/OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function2')
/ENDIF
/ELSE
/IF DEFINED(X)
/OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function3')
/ENDIF
/ENDIF

Which is marginally neater and subscribes to the current syntax. Being able to specify:

/IF DEFINED(COND1)
/IF DEFINED(X) OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function1')
/ENDIF
/ELSEIF DEFINED(COND2)
/IF DEFINED(X) OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function2')
/ENDIF
/ELSE
/IF DEFINED(X) OR DEFINED(Y)
D doStuff PR EXTPROC('function4')
/ELSE
D doStuff PR EXTPROC('function3')
/ENDIF
/ENDIF

is neater still but only because it uses less source lines.

Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.