Query about " warning parameter names (without types) in functiondeclaration"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • prix prad

    Query about " warning parameter names (without types) in functiondeclaration"

    Hi All,
    I encountered the above error when I tried to expand a macro
    as follows:

    #define EXPAND(array) int M_ ## array

    The problem occurs when we have 'array' itself as a macro:

    say EXPAND(ARR(DECL ))
    where #define DECL _decl
    #define ARR(name) arr ## name

    So the end result would be M_arr_name

    The error goes away when I do:

    #define EXPAND(array) int PREPEND_ARR(arr ay)
    where
    PREPEND_ARR(arr ay) M_ ## array

    Can someone explain me why the error is about a 'function declaration'
    in this case since we are dealing with MACROS?

    Thanks,
    /prix
  • Jack Klein

    #2
    Re: Query about " warning parameter names (without types) in function declaration&quo t;

    On Sun, 23 Mar 2008 18:57:17 -0700 (PDT), prix prad
    <maalage@gmail. comwrote in comp.lang.c:
    Hi All,
    I encountered the above error when I tried to expand a macro
    as follows:
    >
    #define EXPAND(array) int M_ ## array
    >
    The problem occurs when we have 'array' itself as a macro:
    >
    say EXPAND(ARR(DECL ))
    "say" what?
    where #define DECL _decl
    #define ARR(name) arr ## name
    The end result of what, exactly?
    So the end result would be M_arr_name
    >
    The error goes away when I do:
    >
    #define EXPAND(array) int PREPEND_ARR(arr ay)
    where
    PREPEND_ARR(arr ay) M_ ## array
    >
    Can someone explain me why the error is about a 'function declaration'
    in this case since we are dealing with MACROS?
    Have you put your macros together in a minimal file and asked your
    compiler to show you its preprocessing output? Virtually all
    compilers provide this feature?

    If so, post the exact contents of that minimal file, all of about
    three lines, exactly. Don't use words to tell us about it, show us
    the actual macro definitions and expansions. And the output of your
    compiler's preprocessor.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c++-faq-lite/
    alt.comp.lang.l earn.c-c++

    Comment

    • Andrey Tarasevich

      #3
      Re: Query about &quot; warning parameter names (without types) in functiondeclara tion&quot;

      prix prad wrote:
      I encountered the above error when I tried to expand a macro
      as follows:
      >
      #define EXPAND(array) int M_ ## array
      >
      The problem occurs when we have 'array' itself as a macro:
      >
      say EXPAND(ARR(DECL ))
      where #define DECL _decl
      #define ARR(name) arr ## name
      >
      So the end result would be M_arr_name
      >
      The error goes away when I do:
      >
      #define EXPAND(array) int PREPEND_ARR(arr ay)
      where
      PREPEND_ARR(arr ay) M_ ## array
      >
      Can someone explain me why the error is about a 'function declaration'
      in this case since we are dealing with MACROS?
      ...
      C preprocessor does not perform preliminary macro expansion for arguments
      adjacent to ## operator. For this reason in your first variant of EXPAND the
      argument ARR(DECL) is not expanded and

      EXPAND(ARR(DECL ))

      first turns into

      int M_ARR(DECL)

      and later, after rescanning into the end result

      int M_ARR(_decl)

      Since 'ARR' get concatenated with 'M_', the preprocessor never gets a chance to
      identify that 'ARR' with your 'ARR' macro.

      This final result looks like a function declaration to the compiler, which is
      why it complains about function declaration.

      In your second variant of EXPAND theres no ## in EXPAND and for this reason in

      EXPAND(ARR(DECL ))

      the preliminary macro expansion is applied to the argument ARR(DECL), resulting in

      int PREPEND_ARR(arr _decl)

      the further rescan turns this into

      int M_arr_decl

      --
      Best regards,
      Andrey Tarasevich

      Comment

      • prix prad

        #4
        Re: Query about &quot; warning parameter names (without types) in functiondeclara tion&quot;

        Hi Andrey,
        Thanks for the lucid explanation.
        Hi Jack,

        The following is the .c file:
        *************** *************** *************** *************** ********
        #define DECL _decl
        #define ARR(name) arr ## name
        #define EXPAND(array) int M_ ## array

        main() {
        EXPAND(ARR(DECL ));
        return 1;
        }
        *************** *************** *************** *************** ********

        The following is the 'gcc -E' output:
        *************** *************** *************** *************** ********
        main() {
        int M_ARR(_decl);
        return 1;
        }
        *************** *************** *************** *************** ********

        Thanks,
        /prix

        Comment

        Working...