'vscode C/C++ Extension: Error squiggles when doing: sizeof(int)

I am using VSCODE in adittion with the C/C++ Extension from Microsoft as a code editor in order to have a more modern code editor than the one my game engine delivers (a code editor from the early 2000s). So I just use vscode to program, I don't compile my code with it.

The problem is that the extension marks correct statements as incorrect: In my case, I get error squiggles for the simple statement: sizeof(int) Intellisense says: "Expression expected C/C++ (29)". Here's a screenshot of this case:

Does anyone of you know what is wrong? Here is a screenshot of my configuration:

Thanks in advance.

I already tried changing the Intellisense mode from msvc-x64 (legacy) to other ones, but the problem still persists.



Solution 1:[1]

sizeof if a built-in keyword, it should never be redefined as a macro. The macro is expanded to a function (I believe _sizeof is a function). The macro expansion looks something like this:

(int)_sizeof(int);

The error you get comes from the argument passed. The macro passed a bare data type in a function call (_sizeof(int)), when in reality arguments to a function in a function call must always be expressions. That is why you got the error "Expected an expression".
One solution could be to place some code like this (at the beginning of your code):

#ifdef sizeof
#undef sizeof
#endif

Let me know if you have any problems.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Shrehan Raj Singh