473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Strange problem in for-loop

Hello,

I have a strange problem with some of my c++ code. I have a normal for-
loop like this

for(int i = 1; .....

on MS-Windows with a Microsoft compiler everything is alright, but
when I compile the same source on Linux with gcc-3.4, the variable "i"
is "0" in the first pass of the loop.

Anyone knows the answer of my problem? Maybe a compiler flag?

Thx!
Markus

Nov 14 '07 #1
6 1363
ma*********@googlemail.com wrote:
I have a strange problem with some of my c++ code. I have a normal
for- loop like this

for(int i = 1; .....
Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.
on MS-Windows with a Microsoft compiler everything is alright, but
when I compile the same source on Linux with gcc-3.4, the variable "i"
is "0" in the first pass of the loop.

Anyone knows the answer of my problem? Maybe a compiler flag?
Maybe. But for the hell of it, I cannot make your program compile
anywhere. My compiler keeps telling me something in line with
"an executable statement outside of any function". I suggest to
look in the FAQ, #5.8.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 14 '07 #2
On 14 Nov., 17:56, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
markus.l...@googlemail.com wrote:
I have a strange problem with some of my c++ code. I have a normal
for- loop like this
for(int i = 1; .....

Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.
I mean a standard for-loop like

for (int i=1; i<10; i++)
{
if(i=9) {...}

}

but "i" start from 0 inside the loop, not from 1 and I don't know why.
This is strange because under windows everything runs fine.

Nov 14 '07 #3
ma*********@googlemail.com wrote:
On 14 Nov., 17:56, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>markus.l...@googlemail.com wrote:
>>I have a strange problem with some of my c++ code. I have a normal
for- loop like this
>>for(int i = 1; .....

Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.

I mean a standard for-loop like

[..]
I mean you need to read the FAQ 5.8 and do what it says. For real!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 14 '07 #4
On Nov 14, 12:15 pm, "markus.l...@googlemail.com"
<markus.l...@googlemail.comwrote:
On 14 Nov., 17:56, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
markus.l...@googlemail.com wrote:
I have a strange problem with some of my c++ code. I have a normal
for- loop like this
for(int i = 1; .....
Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.

I mean a standard for-loop like

for (int i=1; i<10; i++)
{
if(i=9) {...}

}

but "i" start from 0 inside the loop, not from 1 and I don't know why.
This is strange because under windows everything runs fine.
Give us a short, self-contained program that demonstrates the error.
Or, please copy and paste the following program, compile and execute
it, and report back on the results:

#include <iostream>

int main()
{
bool flag = false;
for (int i = 1; i<10; ++i) {
if (i==0) flag = true;
}
std::cout << "Markus was "
<< (flag ? "right" : "wrong")
<< '.';
}

Best regards,

Tom
Nov 14 '07 #5
>>I have a strange problem with some of my c++ code. I have a normal
for- loop like this
for(int i = 1; .....
Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.

I mean a standard for-loop like

for (int i=1; i<10; i++)
{
if(i=9) {...}

}

but "i" start from 0 inside the loop, not from 1 and I don't know why.
This is strange because under windows everything runs fine.
Hmm, if(i=9) {...} *assigns* the value 9 to i (the result of which
evaluates to true). Are you sure that it shouldn't be "=="?
Nov 15 '07 #6
Stefan wrote:
>>>I have a strange problem with some of my c++ code. I have a normal
for- loop like this
for(int i = 1; .....
Not sure what's normal about five periods. I've never seen any
program that would actually use that construct.

I mean a standard for-loop like

for (int i=1; i<10; i++)
{
if(i=9) {...}

}

but "i" start from 0 inside the loop, not from 1 and I don't know
why. This is strange because under windows everything runs fine.

Hmm, if(i=9) {...} *assigns* the value 9 to i (the result of which
evaluates to true). Are you sure that it shouldn't be "=="?
Still, that wouldn't cause the 'i' to "start from 0 inside the loop",
would it? That's why I insist that the OP posts real complete code.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Arthur | last post by:
I've come across some strange xml, that I need to deal with, it looks like this:- <root> <foo attr="1">Some random strange text. <bar attr="2">blar</bar> <bar attr="3">blar blar</bar> <bar...
7
by: M O J O | last post by:
Hi, I'm developing a asp.net application and ran into a strange css problem. I want all my links to have a dashed underline and when they are hovered, it must change to a solid line. Sounds...
0
by: Kris Vanherck | last post by:
yesterday i started getting this strange error when i try to run my asp.net project: Compiler Error Message: CS0006: Metadata file 'c:\winnt\microsoft.net\framework\v1.1.4322\temporary asp.net...
1
by: JoReiners | last post by:
Hello, I have a really strange problem. I'm unable to figure it out on my own. I parse very simple xml documents, without any check for their form. These files look very similar and are encoded...
11
by: Mike C# | last post by:
Hi all, I keep getting a strange error and can't pin it down. The message is: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's...
0
by: AndreasJ.Mueller | last post by:
Hi Since we have moved our application (.NET 1.1) to a new server a few weeks ago we have seen in the event-logs multiple errors (which in itself is not my current problem, so I no...
4
by: Gotch | last post by:
Hi, I'm getting a very strange behaviour while running a project I've done.... Let's expose it: I've two projects. Both of them use a Form to do some Gui stuff. Other threads pack up messages...
14
by: blumen | last post by:
Hi all, I'm a newbie in VB.Net Programming.. Hope that some of you can help me to solve this.. I'm working out to read,parse and save textfile into SQL Server. The textfile contains thousands...
8
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples....
5
by: ioni | last post by:
Good day, fellows! I have a strange problem – at my site there is a flash strip, that loads data dynamically. It works fine (grabs data from the remote server and presents it), however in IE7...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.