Reputation: 12631
#include<stdio.h>
#define A(int x) printf("%d\n",x)
#define AS(A) A(20)
typedef struct{
int *m;
int n;
int k;
}st;
//static st sb[10] = {AS(A)}
int main()
{
AS(A);
return 0;
}
I'm getting an error as below .
Line 14: error: macro parameters must be comma-separated
Please help.
Upvotes: 1
Views: 4443
Reputation: 12112
You dont actually need this : #define A(int x) printf("%d\n",x)
but you need : #define A(x) printf("%d\n",x)
, you don't actually need to declare a variable in preprocessor! ,
Note that :
The preprocessor does not know anything about keywords.
Upvotes: 2
Reputation: 10767
In C, macro parameters aren't typed. It's all symbol substitution . Try this :
#include<stdio.h>
#define A(x) printf("%d\n",x) /*Remove the type */
#define AS(A) A(20)
int main()
{
AS(A);
return 0;
}
see codepad
Upvotes: 3
Reputation: 38183
This has nothing to do with nesting macros. The problem is
#define A(int x) printf("%d\n",x)
you must remove the int
part. Like this:
#define A(x) printf("%d\n",x)
If you leave the int
, the preprocessor interprets it as another parameter, that's why it tells you
Line 14: error: macro parameters must be comma-separated
because expects:
#define A(int,x) printf("%d\n",x)
Upvotes: 7