Sign in to follow this  

c++ language

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

IIRC, which I probably don't, you can compile for either .net or for straight C++. Compiling for .net means you need the .net libraries inorder to run your program, but in exchange you get extra functionality.

Share this post


Link to post
Share on other sites
this will compile in .net, but not in regular C++


for (int i=0; i<5; i++){

}
for (int i=0; i<5; i++){

}



in regular, the variable i is not destroyed so you get errors when redefining it. I really hated that too.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lee_
this will compile in .net, but not in regular C++

*** Source Snippet Removed ***

in regular, the variable i is not destroyed so you get errors when redefining it. I really hated that too.

That is not "regular" C++, that is the bastardized version of C++ that visual studio 6.0 uses. As it was written in 1997 before the standard was finalized (1998). If you are still using 6.0, upgrade. You can get the CLI compiler toolkit free from microsoft, or get a better IDE entirely for about $100. If you wait a while though, 2k5 will be released, and that's even better.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lee_
this will compile in .net, but not in regular C++

*** Source Snippet Removed ***

in regular, the variable i is not destroyed so you get errors when redefining it. I really hated that too.
That will compile in most c++ compilers, it's just vc 6.0 that sucks.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lee_
6.0 for sure, I don't know about the others.. never used them.


This one has benn corercted in VC.NET versions.

To get rid of this problem using VC6, just add


#define for if (1) for


in your stdafx.h header.

HTH

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
To get rid of this problem using VC6, just add


#define for if (1) for


in your stdafx.h header.

Quick question; what should the following program output, and what does it output with that for-hack defined?

int main(int, char **)
{
const int foo = 1;

if(foo == 0)
for(int i = 0; i < 10; ++i) cout << "foo" << endl;
else
cout << "huh?" << endl;
}

Not a problem if you always surround if statements with {}'s, even for single-liners, but it's still a possible error source. Just imagine trying debugging an error like this!

A better for-hack would be this.

#define for if(0); else for

I have not yet seen a situation where the resulting behaviour is different from what it should be. If anyone knows one, feel free to say so.

But of course, the best solution is to get a better compiler.

Share this post


Link to post
Share on other sites

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this