Tathagat Nawadia
Tathagat Nawadia

Reputation: 29

Macros compilation errors in cpp (Visual Studio 2012)

#include <iostream>
#define hello()(printf("Hello");)

using namespace std;

void main()
{
hello();
}

i am using the following code which gives a compilation error !! what could be possibly wrong in this program !!

Upvotes: 1

Views: 49

Answers (1)

Carl Norum
Carl Norum

Reputation: 225032

Parentheses can't be used to enclose statements. What you want is:

#define hello() printf("Hello");

The semicolon is also unnecessary, or maybe you meant:

#define hello() { printf("Hello"); }

Aside from that syntax error, you should probably include cstdio to use printf, and main should return int.

Upvotes: 2

Related Questions