473,387 Members | 1,624 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,387 software developers and data experts.

function doesn't return simply skip the return line

Hello to all, i have the following functions:

string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
return str;
}

the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"

can anyone help me??????????
Jul 21 '08 #1
5 1746
hi*******@gmail.com wrote:
Hello to all, i have the following functions:

string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
return str;
}

the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"

can anyone help me??????????
Since 'qt' is not part of C++, you should consider asking in the
newsgroup (or a web forum) dedicated to that. Apparently the code you
posted cannot be verified without the rest of the stuff (which you did
not post).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 21 '08 #2
On 21 יולי, 17:57, Victor Bazarov <v.Abaza...@comAcast.netwrote:
hirsh....@gmail.com wrote:
Hello to all, i have the following functions:
string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
return str;
}
the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"
can anyone help me??????????

Since 'qt' is not part of C++, you should consider asking in the
newsgroup (or a web forum) dedicated to that. Apparently the code you
posted cannot be verified without the rest of the stuff (which you did
not post).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
maybe, but it skips a regular c++ line of code,
also if i put a cout before the call to return, it prints out (goes
there) but just before
return is supposed to execute, it flies
don't you have any ideas why might that be happening,
isn't my c++ code written well, what else should i post for you to get
the whole picture
?
Jul 21 '08 #3
hi*******@gmail.com wrote:
On 21 יולי, 17:57, Victor Bazarov <v.Abaza...@comAcast.netwrote:
>hirsh....@gmail.com wrote:
>>Hello to all, i have the following functions:
string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
return str;
}
the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"
can anyone help me??????????
Since 'qt' is not part of C++, you should consider asking in the
newsgroup (or a web forum) dedicated to that. Apparently the code you
posted cannot be verified without the rest of the stuff (which you did
not post).

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

maybe, but it skips a regular c++ line of code,
How do you know? Did you step through it in the debugger? If the error
is returned, it's possible that an exception is thrown and then caught
by some invisible code. Qt runs some files through their own "meta
compiler" or something, and who know what kind of code they insert into
what you think is "regular c++"...
also if i put a cout before the call to return, it prints out (goes
there) but just before
return is supposed to execute, it flies
Examine the assembly.
don't you have any ideas why might that be happening,
Nope. Qt is not part of C++, and the sheer fact that you are using it
can render your program incomprehensible from the "regular c++" POV.
isn't my c++ code written well, what else should i post for you to get
the whole picture
?
Again, the code you posted is fine. However, you didn't post enough of
it, for example, what's happening in the 'read()' function?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 21 '08 #4
On 21 יולי, 21:49, Victor Bazarov <v.Abaza...@comAcast.netwrote:
hirsh....@gmail.com wrote:
On 21 יולי, 17:57, Victor Bazarov <v.Abaza...@comAcast.netwrote:
hirsh....@gmail.com wrote:
Hello to all, i have the following functions:
string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
str.append(1,ch);
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
return str;
}
the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
debugging took me to a qt class moc_myclass.cpp (it's a qt project in
eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"
can anyone help me??????????
Since 'qt' is not part of C++, you should consider asking in the
newsgroup (or a web forum) dedicated to that. Apparently the code you
posted cannot be verified without the rest of the stuff (which you did
not post).
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
maybe, but it skips a regular c++ line of code,

How do you know? Did you step through it in the debugger? If the error
is returned, it's possible that an exception is thrown and then caught
by some invisible code. Qt runs some files through their own "meta
compiler" or something, and who know what kind of code they insert into
what you think is "regular c++"...
also if i put a cout before the call to return, it prints out (goes
there) but just before
return is supposed to execute, it flies

Examine the assembly.
don't you have any ideas why might that be happening,

Nope. Qt is not part of C++, and the sheer fact that you are using it
can render your program incomprehensible from the "regular c++" POV.
isn't my c++ code written well, what else should i post for you to get
the whole picture
?

Again, the code you posted is fine. However, you didn't post enough of
it, for example, what's happening in the 'read()' function?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
well, thank you Victor,
in my next post i shell reference your guidance on writing a thread
that
is more understood, and acceptable.
have a good day.

P.S
i guess the capital A was for a new line, but i wasn't innuendoing
anything
next time I will write only letters.
Jul 22 '08 #5
On Jul 21, 4:50 pm, hirsh....@gmail.com wrote:
Hello to all, i have the following functions:
string File::readLine(){
char ch;
string str;
ch = read();
while(ch != LF && ch != CR && ch != -1){
Nothing to do with your problem, but there's no guarantee that a
char can ever take on the value of -1, so you've definitely got
something wrong here. I don't know a read() function which
takes no arguments, so I can't be sure, but the usual idiom
(from C) for this sort of thing is for functions which read a
single character to return an int, with a value in the range
0...UCHAR_MAX, or a negative value for EOF. But this supposes
that the returned value is stored in an int, and not a char.
str.append(1,ch);
Rather than "str += ch"? Strange.
ch = read();
}
if(ch == -1){
cout << "this line could not be read" << endl;
exit(1);
}
//take care of situation where the loop exited with LF but
//on a system that has CR.
int tmp = file->tellg();
Do you know what type ifstream::tellg returns? It isn't int.
if(read() != CR){ //if no CR available on system, return the get
pointer to it's correct location.
file->seekg(tmp);
}
What's the relationship between file and where ever read()
accesses. If read() is accessing file, and file is an istream,
why not use file directly, e.g.:

if ( file->peek() == CR ) {
file->get() ;
}
return str;
}
the function is executed correctly but in the end it skips the "return
str" line,
and tun flies with an error.
What does that mean? "Tun flies with an error." I don't
understand it. If you reach the return statement, it will be
executed. It may cause an exception to be thrown (because str
must be copied, and copying a string may throw), but unless
you're right at the limit in memory use, it's highly unlikely.

Another possibility (very likely, IMHO) is that you've corrupted
the free space arena sometime earlier, and you just happened to
hit the problem when copying str.
debugging took me to a qt class moc_myclass.cpp (it's a qt
project in eclipse)
to a line where it says "_id -= 1;"
inside a function called "int myclass::qt_metacall(...)"
I doubt that that's significant, but you never know. More
likely something else is corrupt, which results in your stack
being corrupted, which results in your returning someplace else
than where you came from.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jul 22 '08 #6

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: joe | last post by:
hi, after reading some articles and faq, i want to clarify myself what's correct(conform to standard) and what's not? or what should be correct but it isn't simply because compilers don't...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
4
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I...
9
by: kernelxu | last post by:
hi,everybody. I calling function setbuf() to change the characteristic of standsrd input buffer. some fragment of the progrem is: (DEV-C++2.9.9.2) #include <stdio.h> #include <stdlib.h> int...
23
by: philipl | last post by:
hi, I have some code here which basically look for within a string, the occurance of any 3 consectative characters which are the same. so AAA bbb etc would be reported by this function. I later...
22
by: SF | last post by:
Hello All, In a windows C learning project I am wokring on I use the system function to run a command, I want to suck the results into a vairable. The system function seems to only return an...
5
by: Ian Bicking | last post by:
I got a puzzler for y'all. I want to allow the editing of functions in-place. I won't go into the reason (it's for HTConsole -- http://blog.ianbicking.org/introducing-htconsole.html), except that...
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.