Visual C++ support of C99 by using "C++ mode" (/TP)

A

albert.neu

To what extent does
Microsoft Visual C++
also called: VC++
also called: Microsoft (R) 32-bit C/C++ Optimizing Compiler

support C99?



VC++ compiles either in C mode (which is def. *not* C99!):
cl.exe /TC c_file.c

or in C++ mode
cl.exe /TP cpp_file.cpp

In C mode (/TC), VC++ is definately *not* conform to C99!




But an interesing question is:
How conform is VC++ to C99, when used in C++ mode (/TP)??

This is particularly interesting, when considering that
the C99 library is part of C++ TR1.
http://groups.google.at/group/comp....6ecb1/95879cd6fca0acc8?hl=en#95879cd6fca0acc8

To what extent does the latest VC++ (in C++ mode /TP) support C++ TR1?
To what extent does the latest VC++ (in C++ mode /TP) use Dinkumware
libraries?




The following is valid C99 code:

/************* c_test.c ***************/
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>

int main( void )
{
bool b = true;
if (b)
printf("hello world\n");

char c = 5;
printf("%hhd\n", c);

int size = INT_MAX / 10000;
printf("%d\n", size);
char a[size];
a[0] = 'a';
a[1] = 'b';
a[2] = '\0';
printf("%s\n", (char *)&a);

return 0;
}


The above C99 code can be compiled on VC++, by just commenting the 2nd
line (see below!)



/************* cpp_test.cpp ***************/
#include <stdio.h>
//#include <stdbool.h>
#include <limits.h>

int main( void )
{
bool b = true;
if (b)
printf("hello world\n");

char c = 5;
printf("%hhd\n", c);

const int size = INT_MAX / 10000;
printf("%d\n", size);
char a[size];
a[0] = 'a';
a[1] = 'b';
a[2] = '\0';
printf("%s\n", (char *)&a);

return 0;
}

To compile with VC++:
cl.exe \TP cpp_test.cpp

Works perfectly! Hmmm... almost C99...???




Comments appreciated,
Albert




Note:
Microsoft VC++ compiler can be obtained for free:
"Visual C++": Microsoft (R) 32-bit C/C++ Optimizing Compiler"

Search
http://www.microsoft.com/downloads
for
"Microsoft Windows SDK for Windows Vista"
On download page; check the "System Requirements":
e.g.
Windows XP Professional SP2 (OK!), Windows Vista, etc.
(Otherwise search for another compatible "Microsoft Windows SDK")

After installing:
The batch-skript for environment variables can be envoked as follows
"C:\Program Files\Microsoft SDKs\Windows\v6.0\bin\setenv.cmd" /
Release /x86 /xp
In setenv.cmd:
'color 07' is normal white on black

Compiler is here:
C:\Programme\Microsoft SDKs\Windows\v6.0\VC\Bin\cl.exe
 
G

Guest

The following is valid C99 code:

/************* c_test.c ***************/
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>

int main( void )
{
bool b = true;
if (b)
printf("hello world\n");

char c = 5;
printf("%hhd\n", c);

int size = INT_MAX / 10000;
printf("%d\n", size);
char a[size];
a[0] = 'a';
a[1] = 'b';
a[2] = '\0';
printf("%s\n", (char *)&a);

return 0;
}


The above C99 code can be compiled on VC++, by just commenting the 2nd
line (see below!)

In other words, by making it valid C++ and invalid C99.

What's your point?
 
R

Richard Heathfield

(e-mail address removed) said:
To what extent does
Microsoft Visual C++
also called: VC++
also called: Microsoft (R) 32-bit C/C++ Optimizing Compiler

support C99?

Because Visual C supports C90, it has de facto support for most of C99
(because most of C99 is basically C90), but it makes no claims of C99
conformance. Neither has Microsoft expressed the slightest interest in
supporting C99 until a significant proportion of their customers
requires it (which doesn't seem to be about to happen any time soon).

<snip>
 
A

albert.neu

The following is valid C99 code:
/************* c_test.c ***************/
#include <stdio.h>
#include <stdbool.h>
#include <limits.h>
int main( void )
{
bool b = true;
if (b)
printf("hello world\n");
char c = 5;
printf("%hhd\n", c);
int size = INT_MAX / 10000;
printf("%d\n", size);
char a[size];
a[0] = 'a';
a[1] = 'b';
a[2] = '\0';
printf("%s\n", (char *)&a);
return 0;
}
The above C99 code can be compiled on VC++, by just commenting the 2nd
line (see below!)

In other words, by making it valid C++ and invalid C99.

What's your point?

My point is:
Maby the difference between VC++ in C++ mode and C99 is marginal.
(In the example above, only the header is not known in the current VC+
+ (but bool is supported anyway))

And maby this difference will get even smaller, if VC++ adopts (or
conforms more closely to) newer C++ standards.

Albert
 
S

Servé Laurijssen

In other words, by making it valid C++ and invalid C99.

What's your point?

My point is:
Maby the difference between VC++ in C++ mode and C99 is marginal.


No it's huge, even in this case where you use bool you will have to remove
stdbool.h references because VC++ doesnt supply the header. Thats not
C99....and theres way more C99 features that wont work no matter how you try
to run the compiler.

try and compile code like this:
struct S s = { .X = 2, .Y = 3, .Z = 4 };
 
P

P.J. Plauger

To what extent does
Microsoft Visual C++
also called: VC++
also called: Microsoft (R) 32-bit C/C++ Optimizing Compiler

support C99?



VC++ compiles either in C mode (which is def. *not* C99!):
cl.exe /TC c_file.c

or in C++ mode
cl.exe /TP cpp_file.cpp

In C mode (/TC), VC++ is definately *not* conform to C99!




But an interesing question is:
How conform is VC++ to C99, when used in C++ mode (/TP)??

This is particularly interesting, when considering that
the C99 library is part of C++ TR1.
http://groups.google.at/group/comp....6ecb1/95879cd6fca0acc8?hl=en#95879cd6fca0acc8

To what extent does the latest VC++ (in C++ mode /TP) support C++ TR1?

Not at all.
To what extent does the latest VC++ (in C++ mode /TP) use Dinkumware
libraries?

We supply the Standard C++ library only, and have done so for over a
decade. But it is our earnest desire to license everything we have
to Microsoft, sooner or later. Note that the next revision of Standard
C++ will include all of the C99 library, as well as most of the rest
of TR1. To the extent that this creates demand from the public,
Microsoft might be interested in adding these features.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
S

Servé Laurijssen

P.J. Plauger said:
Not at all.


We supply the Standard C++ library only, and have done so for over a
decade. But it is our earnest desire to license everything we have
to Microsoft, sooner or later. Note that the next revision of Standard
C++ will include all of the C99 library, as well as most of the rest
of TR1. To the extent that this creates demand from the public,
Microsoft might be interested in adding these features.

If MS does, it might be that little push that C99 needs to be commonly
accepted. Personally I would love to see MSVC with full C99 support.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top