By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

do you know why this is calling segfault in qt?

P: n/a
int nejmensi;
for (int i=1;i<pole.size();i++) {
if (pole.at(i)<pole.at(i-1)) nejmensi=i;
}
return nejmensi;
Aug 10 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Milan Krejci wrote:
int nejmensi;
for (int i=1;i<pole.size();i++) {
if (pole.at(i)<pole.at(i-1)) nejmensi=i;
}
return nejmensi;
"Calling segfault"? As in "undefined behaviour"? <shrugNo,
we don't know. What is 'pole'? Read the FAQ 5.8 before you
proceed.

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

P: n/a
"Milan Krejci" <rd*@mail.czwrote in message
news:f9***********@news.vol.cz...
int nejmensi;
for (int i=1;i<pole.size();i++) {
if (pole.at(i)<pole.at(i-1)) nejmensi=i;
}
return nejmensi;
Could be many reasons, need to see more code.

What happens when pole.size() is 0?
Aug 11 '07 #3

P: n/a
Jim Langston wrote:
"Milan Krejci" <rd*@mail.czwrote in message
news:f9***********@news.vol.cz...
>int nejmensi;
for (int i=1;i<pole.size();i++) {
if (pole.at(i)<pole.at(i-1)) nejmensi=i;
}
return nejmensi;

Could be many reasons, need to see more code.

What happens when pole.size() is 0?
The 'for' loop is not going to be executed. 'nejmensi' is
not initialised. Even returning its value is undefined
behaviour, right?

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

P: n/a
"Victor Bazarov" <v.********@comAcast.netwrote in message
news:6P******************************@comcast.com. ..
Jim Langston wrote:
>"Milan Krejci" <rd*@mail.czwrote in message
news:f9***********@news.vol.cz...
>>int nejmensi;
for (int i=1;i<pole.size();i++) {
if (pole.at(i)<pole.at(i-1)) nejmensi=i;
}
return nejmensi;

Could be many reasons, need to see more code.

What happens when pole.size() is 0?

The 'for' loop is not going to be executed. 'nejmensi' is
not initialised. Even returning its value is undefined
behaviour, right?
Exactly. And whatever used the value of nejmensi will be using an undefined
value. Which may be whats causing the error, we don't know. Need to see
more code. Need to know the actual line the error is occuring on, etc...

It may be the operator< for whatever is stored in pole. Need to see more
code.
Aug 11 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.