One of the series of strange compilation errors in VS2019: use uint8_t and other types to report errors

Recently I wrote a program with a function in a class declared as follows:

virtual void ProcessInput(const uint8_t* keyState);

This statement is normal and there is no syntax error, but the VS2019 compilation fails, and the prompt error is as follows:

Component.h(11,41): error C4430: missing type specifier - int assumed. Note: C++ does not support default int
Component.h(11,41): error C2143: syntax error: missing ',' (before '*')

This is strange, the error reported by the compiler and this statement can be said to be incompatible. This should also be one of the bugs of VS2019 - the compiler is not allowed to report errors. After analysis, I found the root problem.
First, we press CTRL and click on uint8_t and find that its definition is in stdint.h:

//...
typedef signed char        int8_t;
typedef short              int16_t;
typedef int                int32_t;
typedef long long          int64_t;
typedef unsigned char      uint8_t;//就是这一条
typedef unsigned short     uint16_t;
typedef unsigned int       uint32_t;
typedef unsigned long long uint64_t;
//...

I changed the uint8_t in the function declaration to unsigned char, and the compilation passed. Later I found out that the stdint.h file was not included. Add a sentence in front #include<stdint.h>, and the compilation will pass.

Error prompt analysis:
Since we did not include the header file, the VS compiler ignored uint8_t for some reason, so this statement became virtual void ProcessInput(const * keyState);, the compiler thought that I had ignored the parameter type, so it would report the first error. The reason for the second error may be that the compiler thinks that what is in front of const is a parameter, and what is in the back *keyState is a parameter, so the prompt must have a comma.

Note: This problem has been tossing me for several days, VS does not prompt to include header files, prompting such a strange error. It is estimated that most people do not know that there is a header file stdint.h, and no one would think that it is necessary to include this uncommon header file with a type alias. The point is that the code analysis system of VS did not find this error, but it kept reporting errors when compiling, which is really embarrassing. It is recommended that VS improve compilation error messages so that developers can find errors faster.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324104236&siteId=291194637