473,815 Members | 3,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1387
ma*********@goo glemail.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...@com Acast.netwrote:
markus.l...@goo glemail.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*********@goo glemail.com wrote:
On 14 Nov., 17:56, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>markus.l...@go oglemail.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...@go oglemail.com"
<markus.l...@go oglemail.comwro te:
On 14 Nov., 17:56, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
markus.l...@goo glemail.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
1824
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 attr="4">blar blar blar</bar> </foo> </root>
7
1669
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 simple, but it's not working. I've cooked down my output code to show you what I mean. If you run the code below, there's no line under the link, but if you either remove the
0
328
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 files\spsweb\0e3514bf\cb1844e7\assembly\dl2\3b163f 16\00452d31_84e5c301\infragistics.webui.ultrawebgrid.v3.dll' could not be found
1
1560
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 in UTF-8. Now minidom is always able to parse these files with minidom.parse("file") . Now when fetching I use this expression: xmldoc.getElementsByTagName('DocNumb').firstChild.data.encode('latin1')
11
2502
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 support team for more information. However I'm not purposely requesting that the Runtime terminate in an "unusual way." The line that is causing me headaches is:
0
1058
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 Server.Transfer-Comments). What seems very strange is that each corresponding request shows as user agent "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4" even though the requests come from different IPs from all...
4
2104
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 this way like: public class UiMsg { public enum MsgType { StatusOk }; public MsgType Type;
14
3363
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 of rows with about 50 coloums every row.. Everythings goes well until I found one textfile with some strange character...seems to be Japanese character(because it's a Japanese company who owns this textfile)
8
5324
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. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
5
2437
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 and its clones I encounter a strange problem where I can hear clicking sound non-stop (like the page is being reloaded non- stop), whereas the page is not reloading.
0
9735
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10426
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9225
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.