C Programming - C Preprocessor - Discussion

Discussion Forum : C Preprocessor - General Questions (Q.No. 1)
1.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main()
{
    int x=10, y=20;
    SWAP(x, y, int);
    printf("%d %d\n", x, y);
    return 0;
}
It compiles
Compiles with an warning
Not compile
Compiles and print nothing
Answer: Option
Explanation:
The code won't compile since declaration of t cannot occur within parenthesis.
Discussion:
25 comments Page 3 of 3.

Vinay said:   1 decade ago
Why it is not working with parenthesis, while at the same time working with {}?

Manish Atri said:   1 decade ago
@Ravindra Bagale You are right it works with
{c t; t=a; a=b; b=t;}

Puneet said:   1 decade ago
How to correct this program then? (passing 'int' as arg).

Kumaran said:   1 decade ago
(c t; t=a, a=b, b=t) please explain this.
(1)

Padhu said:   2 decades ago
Which parentheis that cannot occur


Post your comments here:

Your comments will be displayed after verification.