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

Discussion in 'C Programming' started by prix prad, Mar 24, 2008.

  1. prix prad

    prix prad Guest

    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(array)
    where
    PREPEND_ARR(array) 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
    prix prad, Mar 24, 2008
    #1
    1. Advertising

  2. prix prad

    Jack Klein Guest

    Re: Query about " warning parameter names (without types) in function declaration"

    On Sun, 23 Mar 2008 18:57:17 -0700 (PDT), prix prad
    <> wrote 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(array)
    > where
    > PREPEND_ARR(array) 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.learn.c-c++
    http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Mar 24, 2008
    #2
    1. Advertising

  3. 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(array)
    > where
    > PREPEND_ARR(array) 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
    Andrey Tarasevich, Mar 24, 2008
    #3
  4. prix prad

    prix prad Guest

    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
    prix prad, Mar 25, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Learner
    Replies:
    1
    Views:
    973
    Marina Levit [MVP]
    Jan 30, 2006
  2. Anonymous
    Replies:
    0
    Views:
    1,440
    Anonymous
    Oct 13, 2005
  3. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    780
    David Gordon
    May 18, 2005
  4. Eric Nelson
    Replies:
    5
    Views:
    1,504
    Alexey Smirnov
    Feb 4, 2009
  5. Jon F.

    CAML Query: Multiple Query Fields Issue

    Jon F., May 12, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    742
    Jon F.
    May 12, 2004
Loading...

Share This Page