IBM Z and LinuxONE Languages

Languages

Languages

Broad range of supported development languages and tools allows to transform software delivery practices.

 View Only
  • 1.  IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Tue January 14, 2020 02:31 PM

    Another newbie sort of question here. I'm trying to create a #define macro that I can use to generate the entry to a routine along with it's #pragma prolog() and #pragma epilog():

    #pragma prolog(<entryname>," <prologasmstuff>")
    #pragma epilog(<entryname>," <epilogasmstuff>")
    functiontype entryname (<parameters>) {


    I've tried a couple of variations of the following (this represents today's attempt):

    #define Entry( \
    EntryType \
    ,EntryName \
    ,EntryVariables \
    ,PrologString \
    ,EpilogString \
    ) \
    _Pragma("prolog(EntryName,\" PrologString\"") \
    _Pragma("epilog(Entryname,\" EpilogString\"") \
    EntryType EntryName (EntryVariables) {

    The preprocessor doesn't seem to be able to make this work. The macro is invoked via:

    Entry(void,wto,char * MsgArea," CKKIP31P"," CKKEP31P")


    and the compiler burps up the following:

    68 |Entry(void,wto,char * MsgArea," CKKIP31P"," CKKEP31P") |
    68 +_Pragma("prolog(EntryName,\" PrologString\"") _Pragma("epilog(Entryname,\" EpilogString\"") void \+
    68 +wto (char * MsgArea) { +

    The compiler issues the following messages:

    WARNING CCN3224 SSAF.METALC.C(TSTENTRY):68 Incorrect pragma ignored.
    WARNING CCN3224 SSAF.METALC.C(TSTENTRY):68 Incorrect pragma ignored.

    Any thoughts on how to see what the "resolved" #pragmas look like or what's wrong with them?

    Thanks,
    Scott Fagen




  • 2.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Wed January 15, 2020 12:12 AM
    Greetings,

    Yes, _Pragma can be used within #define, just need additional steps on String converting.

    I created a testcase based on your attempt. It works during compiling.
    Improvement can be made according to your requirement.

    #define STR(x) #x
    #define STRPROLOG(x,y) prolog(x,#y)
    #define STREPILOG(x,y) epilog(x,#y)

    #define Entry( \
    EntryType \
    ,EntryName \
    ,PrologString \
    ,EpilogString \
    ) \
    _Pragma(STR( STRPROLOG(EntryName,PrologString) )) \
    _Pragma(STR( STREPILOG(EntryName,EpilogString) )) \
    EntryType EntryName (){ \
    return 1234;}

    Entry(int,wto,P1111111,E2222222)

    #pragma prolog(fun1,"P0000001")
    #pragma epilog(fun1,"E0000002")
    int fun1();
    int fun1(){
    return 1;
    }

    Please refer to C/C++ '# operator' for coverting String:
    https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.4.0/com.ibm.zos.v2r4.cbclx01/num.htm

    Also, compile option PROLOG and EPILOG may be used for your own prolog and epilog:
    https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.4.0/com.ibm.zos.v2r4.cbcux01/prolog.htm

    ------------------------------
    He Huang
    ------------------------------



  • 3.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Wed January 15, 2020 09:42 AM
    Hi He...

    Thank you, that is a great suggestion!



  • 4.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Wed January 15, 2020 10:50 AM
    Hi He,

    Thanks, that works...I modified it slightly.  Now for the next question:  how do I get the "results" of the macro to show up in the source listing?

    From the source:


    And here's how it shows up in the compiled listing:


    I can see the "void wto( char * MsgArea)", but how can I get something like:

    #pragma prolog(<content>)
    #pragma epilog(<content>)
    void wto(char * MsgArea)

    ...to show up in the listing.  Here is my current options file, if that helps:

    CSECT
    GENASM
    ILP32
    INLINE
    LIST
    MARGINS(2,*)
    NOSEQ
    METAL
    NOSE
    PLIST(OS)
    RESERVED_REG(r12)
    SE(/usr/include/metal/,'CBC.SCCNSAM')
    LSEARCH('SSAF.METALC.H')
    LSEARCH('C21S.METALC.SAMPLE.H','C21S.METALC.ZOS21.CHDSECT')
    LSEARCH('C21S.METALC.MODGEN21.CHDSECT')
    SKIPS(HIDE)
    SOURCE
    SHOWINC
    XREF
    SS
    EXPMAC

    Thanks,
    Scott


    ​​


  • 5.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Wed January 15, 2020 10:04 PM
    Hi Scott,

    I'm afraid that there is not additional '#pragma prolog() ...' in listing if '_Pragma(...)' is used.

    With EXPMAC (Lists all expanded macros in the source listing) compile option, the expanded Entry(...) is displayed and it contains the _Pragma(...).
    As #pragma and _Pragma statements are equivalent, the expanded Entry(...) in listing could be referred by application programmers.

    ------------------------------
    He Huang
    ------------------------------



  • 6.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Thu January 16, 2020 09:26 AM
    Ok.  And, as you can't generate comments inside a #define macro, there's no way to make it more readable. 

    It is what it is, *sigh*.

    Are there any c/c++ macro language pre-processors that could be put "in front" of the ​compile step so that we might accomplish more complex "feats of stupidity" than allowed for by the pre-processor included with the language (I realize this isn't an IBM problem so much as a c/c++ language definition problem).  

    Does the IBM team have any thoughts of perhaps making something like the PL/X macro processor available [on/through/with] (not sure of the right preposition) the XL/C compiler?  I realize this brings up questions of portability, but once you are talking about Metal C, the portability discussion really goes out the window.

    Thanks,
    Scott


  • 7.  RE: IBM z/OS Metal C - Can I create a #define macro that includes #pragma statements?

    Posted Fri January 17, 2020 01:43 AM
    Scott,

    For other preprocessor directives, please refer to 'z/OS XL C/C++ Language Reference'.
    If there are any new requirements about XL/C or PL/X, you are welcomed to raise Request For Product Enhancement (RFE). The development team will evaluate the RFEs and consider about them.

    ------------------------------
    He Huang
    ------------------------------