Topic
  • No replies
Michael_Wong
Michael_Wong
29 Posts

Pinned topic How do you determine the compiler's predefined macros?

‏2009-02-03T20:40:29Z |
Recently, I had an interesting question from someone internal about how to figure out what macros are preprocessed and their final replaced values. Well, we implemented an option in V10.1 Compiler to support that.

This is the -qshowmacros option along with the -P or -E option. This feature first became available in the V10.1 compiler.

Now you can use a trick to find out what are the predefined macros set by the compiler.

The trick is to compile an empty source to tell you what the compiler predefines:


int main()
{
return 0;
}


Now compile this as
xlC -qshowmacros -P t.C
You will see the entire list of predefined macros in the t.i file:

This shows the following 75 macros are predefined for the V10.1 C++ compiler

#define _POWER 1
#define _IBMR2 1
#define _AIX53 1
#define _AIX52 1
#define _AIX51 1
#define _AIX50 1
#define _AIX43 1
#define _AIX41 1
#define _AIX32 1
#define _AIX 1
#define __IBM_INCLUDE_NEXT 1
#define __IBM_MACRO_WITH_VA_ARGS 1
#define __C99_MACRO_WITH_VA_ARGS 1
#define __C99__FUNC__ 1
#define __EXCEPTIONS 1
#define _CPPUNWIND 1
#define __DIGRAPHS__ 1
#define __LONGDOUBLE64 1
#define __IBM__ALIGN 1
#define __ALIGN 1
#define __C99_HEX_FLOAT_CONST 1
#define __IBM_ATTRIBUTES 1
#define __IBM_EXTENSION_KEYWORD 1
#define __IBM__TYPEOF__ 1
#define __IBM__ALIGNOF__ 1
#define __C99_PRAGMA_OPERATOR 1
#define __IBM__RESTRICT__ 1
#define __C99_RESTRICT 1
#define __BOOL__ 1
#define __OBJECT_MODEL_CLASSIC__ 1
#define __OBJECT_MODEL_COMPAT__ 1
#define __NO_RTTI__ 1
#define defined defined
#define __IBM_COMPUTED_GOTO 1
#define __IBM_LABEL_VALUE 1
#define __C99_VARIABLE_LENGTH_ARRAY 1
#define __C99_COMPOUND_LITERAL 1
#define __IBM_UTF_LITERAL 1
#define __IBM_LOCAL_LABEL 1
#define __XPLINK_CALLBACK__ 1
#define _LONG_LONG 1
#define __CHAR_UNSIGNED__ 1
#define _CHAR_UNSIGNED 1
#define _ARCH_PPC 1
#define _ARCH_COM 1
#define __IBM_GCC_ASM 1
#define _EXT 1
#define _MI_BUILTIN 1
#define __BASE_FILE__ "e.C"
#define __V6ALIGN__ 1
#define __XLC13__ 1
#define __XLC121__ 1
#define __MATH__ 1
#define __STR__ 1
#define _WCHAR_T 1
#define __TOS_AIX__ 1
#define __THW_RS6000__ 1
#define _ILP32 1
#define __ppc__ 1
#define __PPC__ 1
#define __PPC 1
#define __powerpc__ 1
#define __powerpc 1
#define __BIG_ENDIAN__ 1
#define _BIG_ENDIAN 1
#define __THW_PPC__ 1
#define __THW_BIG_ENDIAN__ 1
#define __FUNCTION__ __FUNCTION__
#define __STDC__ 0
#define __xlC__ 0x0a01
#define __HOS_AIX__ 1
#define __HHW_RS6000__ 1
#define __HHW_BIG_ENDIAN__ 1
#define __IBMCPP__ 1010
#define __cplusplus 199711L


For the C compiler, we have 104 macros:

#define __PPC 1
#define __IBM_LOCAL_LABEL 1
#define __C99_HEX_FLOAT_CONST 1
#define __CHAR_UNSIGNED__ 1
#define __const__ const
#define __IBM_DOLLAR_IN_ID 1
#define __C99_FLEXIBLE_ARRAY_MEMBER 1
#define _ARCH_COM 1
#define __C99_STATIC_ARRAY_SIZE 1
#define __C99_MIXED_DECL_AND_CODE 1
#define __HHW_BIG_ENDIAN__ 1
#define __LONGDOUBLE64 1
#define __typeof __typeof__
#define __C99__FUNC__ 1
#define __XLC121__ 1
#define __ALIGN 1
#define __C99_STD_PRAGMAS 1
#define __PPC__ 1
#define __C99_EMPTY_MACRO_ARGUMENTS 1
#define __BASE_FILE__ "e.c"
#define _AIX 1
#define __THW_PPC__ 1
#define __C99_DESIGNATED_INITIALIZER 1
#define __BIG_ENDIAN__ 1
#define __C99_NON_LVALUE_ARRAY_SUB 1
#define __powerpc__ 1
#define __IBM_GENERALIZED_LVALUE 1
#define __STDC__ 1
#define __C99_MACRO_WITH_VA_ARGS 1
#define __STDC_HOSTED__ 1
#define __const const
#define __THW_RS6000__ 1
#define __unix 1
#define __IBM_REGISTER_VARS 1
#define __IBM_ATTRIBUTES 1
#define __alignof __alignof__
#define __IBMC__ 1010
#define __TOS_AIX__ 1
#define __C99_COMPOUND_LITERAL 1
#define _ARCH_PPC 1
#define __IBM__IMAG__ 1
#define __IBM__TYPEOF__ 1
#define __IBM_INCLUDE_NEXT 1
#define __IBM_PP_PREDICATE 1
#define __DIGRAPHS__ 1
#define __FENCE 1
#define __IBM_COMPUTED_GOTO 1
#define __IBM__REAL__ 1
#define _ILP32 1
#define __C99_TGMATH 1
#define __THW_BIG_ENDIAN__ 1
#define __HHW_RS6000__ 1
#define __C99_DUP_TYPE_QUALIFIER 1
#define __GCC_PROTO_OVERRIDES_KNR_DEF 1
#define __MATH__ 1
#define __HOS_AIX__ 1
#define __FUNCTION__ __FUNCTION__
#define __signed signed
#define __IBM_EXTENSION_KEYWORD 1
#define __C99_INLINE 1
#define __C99_UCN 1
#define __IBM_GCC_ASM 1
#define __signed__ signed
#define __IBM_LABEL_VALUE 1
#define __SIZE_TYPE__ unsigned int
#define __XLC_BUILTIN_VAARG__ 1
#define __C99_LLONG 1
#define __IBM_MACRO_WITH_VA_ARGS 1
#define _AIX32 1
#define _AIX41 1
#define _AIX43 1
#define __volatile volatile
#define _AIX50 1
#define _AIX51 1
#define _AIX52 1
#define _AIX53 1
#define __C99_VAR_LEN_ARRAY 1
#define __BOOL__ 1
#define __xlC__ 0x0a01
#define __STDC_VERSION__ 199901L
#define __IBM_ALIGNOF__ 1
#define __C99_NON_CONST_AGGR_INITIALIZER 1
#define __C99_MAX_LINE_NUMBER 1
#define __ILP32__ 1
#define _BIG_ENDIAN 1
#define __C99_COMPLEX 1
#define __C99_BOOL 1
#define __IBM_GCC__INLINE__ 1
#define __C99_PRAGMA_OPERATOR 1
#define __C99_RESTRICT 1
#define __C99_MIXED_STRING_CONCAT 1
#define _LONG_LONG 1
#define __IBM_NESTED_FUNCTION 1
#define __XLC13__ 1
#define __unix__ 1
#define __STR__ 1
#define __powerpc 1
#define _CHAR_UNSIGNED 1
#define __volatile__ volatile
#define _POWER 1
#define __C99_CPLUSCMT 1
#define __IBM_PP_WARNING 1
#define __xlc__ "10.1.0.2"
#define _IBMR2 1
Updated on 2009-10-15T12:08:57Z at 2009-10-15T12:08:57Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    196 Posts

    Re: How do you determine the compiler's predefined macros?

    ‏2009-10-15T12:08:57Z  
    Those on z/OS will not be able to use this option till V1R11. A workaround for prevous releases is to use makedepend utility. Have a look at the -Wm,list option which will produce a depend.lst file with sections almost identical to the above output.

    Makedepend utility however is being deprecated with the introduction of the -qmakedep in zOS V1R11.

    Some relates information at the bottom of this post
    Updated on 2009-10-15T12:08:57Z at 2009-10-15T12:08:57Z by SystemAdmin
  • erik_o
    erik_o
    1 Post

    Re: How do you determine the compiler's predefined macros?

    ‏2013-10-01T14:38:12Z  
    Those on z/OS will not be able to use this option till V1R11. A workaround for prevous releases is to use makedepend utility. Have a look at the -Wm,list option which will produce a depend.lst file with sections almost identical to the above output.

    Makedepend utility however is being deprecated with the introduction of the -qmakedep in zOS V1R11.

    Some relates information at the bottom of this post

    A propos this, what do you do on z/OS to enable the __C99_NON_CONST_AGGR_INITIALIZER macro? I am on V1.13.

    When I run xlc -qLOCALE="Sv_SE.IBM-278" -E -qshowmacros=all myfile.c | grep C99, i.e. langlevel = extended, I get a list of most of the C99 macros from the Language reference, but the above is oddly enough missing. The said manual does not state that there is anything special about this particular one. Anyone knows? Thanks.

    Updated on 2013-10-01T14:39:16Z at 2013-10-01T14:39:16Z by erik_o
  • xlsup_lac
    xlsup_lac
    4 Posts

    Re: How do you determine the compiler's predefined macros?

    ‏2013-10-02T15:25:20Z  
    • erik_o
    • ‏2013-10-01T14:38:12Z

    A propos this, what do you do on z/OS to enable the __C99_NON_CONST_AGGR_INITIALIZER macro? I am on V1.13.

    When I run xlc -qLOCALE="Sv_SE.IBM-278" -E -qshowmacros=all myfile.c | grep C99, i.e. langlevel = extended, I get a list of most of the C99 macros from the Language reference, but the above is oddly enough missing. The said manual does not state that there is anything special about this particular one. Anyone knows? Thanks.

    Hi Erik - good catch!  This looks like a bug in the compiler.  The xlc invocation certainly supports non-constant aggregate initializers, so we might be forgetting to set the __C99_NON_CONST_AGGR_INITIALIZER macro.  I've added this issue to our records.  Thanks!!