473,698 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_met acall(...)"

can anyone help me??????????
Jul 21 '08 #1
5 1766
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_met acall(...)"

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...@com Acast.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_met acall(...)"
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...@com Acast.netwrote:
>hirsh....@gmai l.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_met acall(...)"
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 incomprehensibl e 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...@com Acast.netwrote:
hirsh....@gmail .com wrote:
On 21 יולי, 17:57, Victor Bazarov <v.Abaza...@com Acast.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_met acall(...)"
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 incomprehensibl e 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_met acall(...)"
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 objektorientier ter Datenverarbeitu ng
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
4963
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
2
3631
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 support. (first i compiled them with g++3.x. ERR means compiler will bark, otherwise it does accept it. Then the Comeau C/C++ 4.3.3 comes)
8
4830
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
2663
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 can avoid problems with it in the future. If there are any references I should check out let me know. Full highlighted code at:
9
4004
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 main(void) { char buf = {0};
23
1823
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 added some code which is needed to detect the scenario where the same char appears 4 times for example AAAA, in this case want to skip the remaining 3 chars and check the next character in the string. This has led me to increase my for loop...
22
2828
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 int. I would like to know how could this is done? I can see only one way currently and I know that there must be a better method. Right now I would be tempted to pipe the output of the command to a temp file and then get the data from the file....
5
1978
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 I really want to edit it all in-process and in-memory. So I want the identity of the function to remain the same, even as I edit the body and hopefully the signature too. Well, the reason is that I want to edit any function object, without...
10
1884
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 to vector3; //this conversion just returns positon Vector3 position;
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9026
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
8893
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
7723
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...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4366
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
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.