0

When I compile a C++ program, Visual Studio shows several error messages, as shown in the screenshot below: error about C standard library

The strange thing is that the error-related header files (such as cstdint or stdint.h) are not written by myself, but the official, standard header files. Since these header files are official standard header files, they should be correct and not cause errors.

Here are some more specific error messages, such as line 25 of the cstdint file. The error message about this line is shown in the screenshot below:

line 25 in the file cstdint

The strange thing is that only the type in line 25 is colored purple, and the types in the other lines are colored green.

The line 25 where error occurred is:

using _CSTD int64_t;

Thank you for reading my question, I would like to know what caused this error and it would be a pleasure to receive your answer.

  • 1
    Your code obviously contains an `#include` line that (probably indirectly) tells the compiler to read the file `cstdint`. Therefore you got the error message. I suggest to generate the preprocessor output and search for `int64_t` and `int32_t`. I expect that `int32_t` is found, but the `int64_t` in the next line is replaced by `long`. That can be done by a `#define int64_t long` somewhere else. – harper Jun 14 '23 at 09:02
  • @harper Yes, there is another line `#define int64_t long long int` in my program written by me. But does that line caused this problem? Why? There is a line `typedef long long int64_t;` in the file “stdint.h”, which is provided by C standard libraries instead of me. But those two lines have the same meaning, don't they? They all mean: new type int64_t is long long int. So, since those two lines have the same meaning, it seems that the error was not caused by the line `#define int64_t long long int` in my program written by me. –  Jun 14 '23 at 10:30
  • @harper But, the fact is quite the opposite. If I delete this line `#define int64_t long long int` in my program, there will be no error. The problem is caused by `#define int64_t long long int` . –  Jun 14 '23 at 10:35
  • No, those lines don't have the same meaning; with your macro, `typedef long long int int64_t;` becomes `typedef long long int long long int;`. How did you get the idea to define that macro? – molbdnilo Jun 14 '23 at 11:43
  • You didn't follow my suggestion to generate the preprocessor output. With your `#define int64_t long long int` you will get `using _CSTD long long int;`. In that line of code the type `long` is unexpected as the compiler said. That's why the error vanished as you deleted the `#define`. – harper Jun 14 '23 at 12:49
  • Take a good C book and look for the difference between a type and a macro. – harper Jun 14 '23 at 12:51

0 Answers0