Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weird problems in .NET 2003

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
My company insists to use MS products. So I am stuck with that. Here is my problem...

in .NET 2003
1. char *name = new char[256]; is valid but not in VStudio 6.0
2. bool isNeg = false; is valid but not in VStudio 6.0
3. double my_arr[3] = {0.3, 0.4, 0.8}; is valid but not in VStudio 6.0

I am trying to port some testing code into VStudio 6.0.

Is there some library Im missing? Ive included stdio, stdlib, math.
 
Well the first two lines are not even valid C - they're both from C++ land.
The third depends on where you declare it, you may be relying on C++ features with that as well.




--
 
Thanks Salem. You were right about all 3. Stupid .NET...it seems I can write a C Program in .NET and slip in a 'cin' command and the compiler just compiles it. I get mixed up between C and C++ and rely on the compiler to let me know.

 
Well, a valid C program is a valid C++ program, as far as the compiler is concerned. If you write a complete C program, a C++ compiler will compile it just fine. It's when you try to slip C++ into a C program that you get the problems.

.NET is supposed to be "multilingual", so it (I assume) parses the code file and picks the best compiler for it. Hence, what works in .NET is not always going to work in VC6, where (again, I assume) you pick whether to use a C or C++ compiler.
 
> Well, a valid C program is a valid C++ program, as far as the compiler is concerned.
No it isn't.
There are many perfectly valid C programs which either do not compile at all as C++, or if they do, produce different answers.

> so it (I assume) parses the code file and picks the best compiler for it.
Again, no. Imagine the chaos as the compiler toggles between C and C++ based on very minor edits in your code!

The compiler initially chooses the language from the file suffix - a .c file would be a C program, a .cpp file would be a C++ program.

Life isn't helped for the C programmers by the IDE choosing .cpp by default, because it's something a lot of people forget to change, and they slip into C/C++ mode all too easily.

If you really want to be sure which language you're using, then use the command line flags
microsoft help said:
/Tc or /TC Specifies a C source file
/Tp or /TP Specifies a C++ source file
Type [tt]cl /?[/tt] at the command prompt or visit here for more.

--
 
>> Well, a valid C program is a valid C++ program, as far as the compiler is concerned.
> No it isn't.
>
Touche...Most of them are, though--provided the C program is not using a handful of C++-only keywords as identifiers.

>There are many perfectly valid C programs which either do >not compile at all as C++, or if they do, produce >different answers.

A program producing different answers doesn't make it invalid. "...as far as the compiler is concerned." The compiler doesn't care if your answers are different. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top