× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello, Simon:

I find that when using any preprocessor-type compiler directives, in any language, it is best to keep the conditions very simple. If it requires a more complex conditional test, with ANDs and ORs etc., I find it is usually better to code that logic within the HLL language itself, e.g. using real "if" statements, where the values to be tested are initialized at compile-time and are never altered by the program, and so the compiler "back-end" recognizes this and will usually "optimize out" any unused branches (so-called "dead code" removal). This also makes for much more readable source code, in my opinion.

In your particular example, you could declare "doStuff" as a procedure pointer, and in an *INZSR, initialize it to the appropriate procedure pointer e.g., using the QleActBndPgm API to dynamically load/activate the needed *SRVPGM(s) and then calling the QleGetExp API to resolve to any needed procedure(s) within that service program, assigning the appropriate pointers (to "doStuff").

Then, the rest of the application just calls "doStuff" as usual, and at runtime it will point to the correct procedure.

Does this make sense?

Cheers,

Mark S. Waterbury

> Simon Coulter wrote:

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.