FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


ick. . . i hate weird compilers





01000101
ok, so i use DEV/C++ on my windoze box, and i compile a program with the lines

Code:
for (i=0;i<100;i+2)
{ statements }


and it compiles nicley on DEV, and "i" now adds in incriments of two..
but if i compile with the SAME EXACT code on VC++ of my unix gcc/g++... then i get errors saying that the "i"+2 needs to be "i"++ , which i understand, but i dont want it to be i++, i want it to be i+2, or i+++... can someone tell me how to do the same thing with the for loop in VC++?
AftershockVibe
Convert it to a while loop instead of using FOR. Syntax may not be exact as I don't know the language...

Code:

i=0;
while(i<100)
{
statements
i = i + 2;
}
01000101
thnx, i thought there might be another way to get around the oversensitive compiler of VC++, but the do/while loop does the same functioning..

Pe@cE
Liu
You can attempt i++++;
Kaneda
The C for-loop has always seemed to be a strange beast, since it's almost too versatile... The actual definition is:

Code:
for (expression; expression; expression) statement


... but most people I know of think of it as:

Code:
for (statement; expression; statement) statement


... or even more specifically:

Code:
for (initializer; condition; incrementer) statement


All those definitions hold because most (if not all) statements in C are also expressions. "y = 2;" equals 2 for example, which is why you can do "x = y = 2;".

Your code actually only fits with the first definition, and in reality, if it worked, it would be pretty useless. More specifically, it would cause an infinite loop. Because you never actually change the value of i. But it should, as far as I'm aware be valid code, even if most compilers (sensibly) won't allow it.

"i+2" isn't an incrementer, it's not a statement either, it's an expression yielding "i plus 2", but not assigning or using that value anywhere.

The short version: I think you'd want to use:

Code:
for (i = 0; i < 100; i += 2)


Note the "+=" replacing the "+" Wink
Liu
Kaneda wrote:

Code:
for (i = 0; i < 100; i += 2)


Note the "+=" replacing the "+" Wink

We have a winner.
01000101
Magnificent. Thank you a ton, i can see why the compiler would have conflicting interests in this case.. i still want to know why my DEV/C++ compiler worked like a charm with the origional statement, maybe it has some sort of safeguard for those things.

thanks again.
im going to close this topic down because its no longer needed.

Pe@cE
Related topics
Your Favorite Movie
WWE Wrestling
I hate school
... And the browser trophy goes to ...
Top Chinese General Warns US Over Attack
Ausse Minister Brendan Nelson to Tony Blair:
porn virus
LINCOLN/KENNEDY - Weird History Lesson
My complaint with today's music
Federal 'Hate Crimes' Bill Threatens Religious Freedoms
My Weird Phobia - prepare to laugh!
Stranged thing ever happend on your pc
The hate for the existing GOD...
Just hate Guinness World Records!
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.