Why there is error message about "__int64" when it's not even used in my code?

423 views Asked by At

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.

1

There are 1 answers

0
Jerry Coffin On

Back before the C++ standard added long long as a standard type with a minimum of 64 bits, Microsoft added a type named __int64 to 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 long to C++, Microsoft seems to have implemented it as an alias for their existing __int64 type. So, when you use long long, the compiler internally "thinks" of that as meaning __int64.

In your code, after the macro is expanded, you have:

typedef long long long long int;

In parsing this the compiler treats the first long long as meaning __int64. That's then followed by another long, and parsing fails. When it prints out the error message, it prints out long long using its internal name for that 64-bit type (__int64).