[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: #ifndef main
From: |
Bernd Strieder |
Subject: |
Re: #ifndef main |
Date: |
Fri, 25 Jul 2008 17:00:10 +0200 |
User-agent: |
KNode/0.10.4 |
Hello,
awhan.iitk@gmail.com wrote:
> I have two files and the contents are as follows :
>
> file :: main.h
> -------------------------------------
> #define main
> --------------------------------------
> file :: main.cpp
> -------------------------------------
> #include "main.h"
>
> int main(void)
> May somebody please shed some light on this ?
Everything with those # at the beginning of the line is handled by the
preprocessor before the actual compiler gets its input. That
preprocessor is basically able to replace identifiers by arbitrary
strings. So
#define main
will send every identifier "main" to the empty string. A macro named
main with empty value has been defined.
You can see the result with
g++ -E main.cc
and then you will understand the compiler error message.
Try the following: #define main foobar
or even: #define main(x) main(int argc)
I think the textbooks on C++ explain the preprocessor as far as
necessary, because there is no way around in any real-world project.
Bernd Strieder