I wrote the code below:
#define int64_t long long int
typedef long long int64_t; //this line is line 2
void main()
{
int64_t a;
}
When I complied this program, the compiler displayed an error message: in line 2, '__int64' followed by 'long' is illegal.
But the strange thing is that there is no "__int64" in my code, only "int64_t", but "int64_t" and "__int64" are spelled differently, so they are totally different variables. Yes, it is wired that an error about a variable which never appears in my code occurred. What is wrong about line 2, and how does this line cause this error?
Thank you for reading and hope to receive your valuable answers.
Back before the C++ standard added
long longas a standard type with a minimum of 64 bits, Microsoft added a type named__int64to their compiler to provide the same basic capability, but with a name that was a conforming extension to C (i.e., names starting with an underscore followed by another underscore or an upper-case letter are reserved for the implementation).When the C++ committee got around to adding
long longto C++, Microsoft seems to have implemented it as an alias for their existing__int64type. So, when you uselong long, the compiler internally "thinks" of that as meaning__int64.In your code, after the macro is expanded, you have:
In parsing this the compiler treats the first
long longas meaning__int64. That's then followed by anotherlong, and parsing fails. When it prints out the error message, it prints outlong longusing its internal name for that 64-bit type (__int64).