11-22-2009 10:10 AM
Bonjour,
One quick question about enabling variable initialisation in for loop definition
I can compile an run the code below in CVI in debug mode
#include <cvirte.h>#include <stdio.h>int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ for (int i=0; i<3; i++){ printf("Hello Dude\n"); } printf("Press ENTER to exit:"); getchar(); return 0;}
Now I use MSVC 2009 Express edition as an external compiler when I want to compile the Release version
When I try to compile then I got warnings and errors because of the declaration of the variable "i" in the for loop
I though the Microsoft extensions were enabled by default.
Anyway... I went thru the options of the external compiler support
I tried to include the /Ze flag as an additional flag in the External Compiler Setup Dialog box
No way...even with the /Ze flag
When compiling the release version of the code with MSVC 2009, it seems the the declaration of "i" as an int is still a problem
Is there sometinig I missed?
Any idea ?
Regards, Philippe
11-22-2009 04:27 PM
You've just discovered that Microsoft doesn't support C99 language features in the Visual Studio C++ compiler.
The native CVI compiler in release mode does support in-block variable declarations, as does the Intel C++ compiler for windows when you use it as the release compiler.
It appears also that Microsoft has no intention of ever making the VC++ compiler support the C99 extensions.
Menchar
11-23-2009 03:55 AM
Have you tried it with the /TP flag? I don't know if this is supported by the Express version, but it should force C++ compilation rules, including making your declaration legal.
JR
11-23-2009 11:01 AM
That'll work so long as he writes "clean C" that's in the common subset of C89 (plus the C99 features that NI has added) and C++.
This essentially means to always use function prototypes and not use C++ keywords such as "class" and "virtual". There are several other areas where conflicts could arise though maybe rarely. See H&S 1.1.5.
Menchar