468,484 Members | 1,762 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

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(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
Mar 24 '08 #1
3 3788
On Sun, 23 Mar 2008 18:57:17 -0700 (PDT), prix prad
<ma*****@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(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
Mar 24 '08 #2
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
Mar 24 '08 #3
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
Mar 25 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by cyber0ne | last post: by
11 posts views Thread by Charles Sullivan | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.