I am using MDK-ARM V5.37 with arm compile V5 and have noticed that _MSC_VER is defined until I perform a build at which point it becomes undefined.
I have no idea where/why it is defined, it certainly isn't in my code. I don't understand why it is defined and then becomes undefined at the point I perform a build.
It can easily be demonstrated in "main.c" as follows:
#if defined(_MSC_VER) && _MSC_VER >= 1700 int a = 1; #endif int main(void) { int b = a; /* Infinite loop */ while (1) { } }
The Dynamic Syntax Checker is happy with the code and "int a = 1;" is not greyed out, implying _MSC_VER is defined.
Now compile the code and it gives error in main() stating that "a" is undefined.
This only happens when configured for arm compiler V5. When configured for arm compiler V6 "int a = 1;" is greyed out and _MSC_VER is not defined before/during build.
Parentheses? Maybe something in the language changed regarding precedence?
Nothing like that I'm afraid. There is no doubt that _MSC_VER is defined until the build is started. Try it yourself and you will see.
Actually, no. There is in fact all kind of doubt, mostly because the phrase "until the build is started" makes no sense.
What most likely happens is that for some silly reason this macro (which is supposed to identify the Microsoft C compiler for Windows) is believed to be defined by the Syntax checker engine, but it is (quite correctly) not defined for the compiler. Those are two separate tools, not two different points in time, which is why the qualifier "until" makes no sense here.
I'm merely stating the way it behaves - you're being pedantic. I will rephrase - it BEHAVES as if it is defined but when the build starts it is clearly not defined as code within the #if is not compiled. This behaviour is only seen when project configured for V5 compiler, not V6. It may well be a problem with the DSC as it is likely to be influenced by the compiler version.
The most likely reason is, that in uVision the compiler to compile the source, Arm Compiler 5, is different to the compiler used for DSC, Arm Compiler 6/clang. The Arm Compiler 6/clang defines the _MSC_VER on Windows and the Arm Compiler 5 does not know it. There are other situations when the DSC might report errors on Arm Compiler 5 specific syntax, like embedded assembler usage.
Not sure what your code should actually achieve. There are already discussions out there, like this on Stack Overflow, also mentioning how to check for specific compilers, if this is what you want to do.
The problem with _MSC_VER being defined as far as DSC is concerned for compiler v5 is as follows:
"platform_util.h" in mbedTLS includes <sal.h> if _MSC_VER is defined. This file does not exist on my PC. Therefore the DSC flags it with a red X and everything thereafter is ignored by the DSC. This results in DSC not working for any file that includes mbedTLS headers. I have raised a support ticket for this.