473,324 Members | 2,567 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,324 software developers and data experts.

debug gives different result than run

I have this class A that contains a method A_method that opens a file
and does fgets.

I also have a template class B that contains a method B_method that
takes a class A object as template type. B_method then uses this A
object to call A_method.

here is a snippet (pseudo)

In class A.cpp:
===============
B <A> myVar;

// method that uses method of template class
A::someMethod(){
myVar.B_method(this);
Jul 23 '05 #1
4 1663
"marcus" <ma************@koping.net> wrote in message
news:1a*************************@posting.google.co m...
I have this class A that contains a method A_method that opens a file
and does fgets.

I also have a template class B that contains a method B_method that
takes a class A object as template type. B_method then uses this A
object to call A_method.

here is a snippet (pseudo)

In class A.cpp:
===============
B <A> myVar;

// method that uses method of template class
A::someMethod(){
myVar.B_method(this);
.
.
}

// method to be called from template class
A::A_method(char *fileName){
char iLine[200];
int meshCount = 0;

FILE *stream = fopen(fileName, "r");
//geometryData = NULL;
if(stream != NULL){
// loop through parsing every line in the file
while (fgets(iLine, 200, stream) != NULL){
.
.
}
}
}

In class B.h:
=============
B<TAG>::B_method(TAG *A_object)
{
.
.
A_object->A_method(fileName)
}

The 1st method that is invoked above is A::someMethod
The problem is that when running the application the fgets makes the
application crash (the _cnt component has the value -1). When
debugging the application though everything works fine.

Your shown code has become a bit too pseudo.
There is no _cnt component and from what is
shown, there is no visible reason for the fgets()
call to fail with a fault.

It is common, when one has induced undefined
behavior, for that behavior to change when the
build settings change.

You may want to provide some real but reduced
code that duplicates your problem. Alternatively,
learn to modify your non-debug build so that you
can use the debugger and debug it.

--
--Larry Brasfield
email: do***********************@hotmail.com
Above views may belong only to me.
Jul 23 '05 #2

"marcus" <ma************@koping.net> wrote in message
news:1a*************************@posting.google.co m...
I have this class A that contains a method A_method that opens a file
and does fgets.

I also have a template class B that contains a method B_method that
takes a class A object as template type. B_method then uses this A
object to call A_method.

here is a snippet (pseudo)

In class A.cpp:
===============
B <A> myVar;

// method that uses method of template class
A::someMethod(){
myVar.B_method(this);
.
.
}

// method to be called from template class
A::A_method(char *fileName){
char iLine[200];
int meshCount = 0;

FILE *stream = fopen(fileName, "r");
//geometryData = NULL;
if(stream != NULL){
// loop through parsing every line in the file
while (fgets(iLine, 200, stream) != NULL){
.
.
}
}
}

In class B.h:
=============
B<TAG>::B_method(TAG *A_object)
{
.
.
A_object->A_method(fileName)
}

The 1st method that is invoked above is A::someMethod
The problem is that when running the application the fgets makes the
application crash (the _cnt component has the value -1). When
debugging the application though everything works fine.


Code that exhibits such behavior is very likely to cause some undefined
behavior in previous sections before your program breaks down. Most probably
the problem is not fgets() but might be found before. Use your debugger to
break before fgets is executed and check the variables & pointers that are
around.

HTH
Chris
Jul 23 '05 #3
Thanks for answering.

"Larry Brasfield" <do***********************@hotmail.com> wrote in message
Your shown code has become a bit too pseudo. Yes maybe I am sorry for this, I will shortly try to post some code
that is more of the actual code I am using.
There is no _cnt component the _cnt component is an element of the FILE datatype. I think it is
supposed to have the value of the number of bytes read (this showing
-1 when I run is not a good sign :-( ).
You may want to provide some real but reduced
code that duplicates your problem.

I will try to do that shortly
Jul 23 '05 #4
Problem solved!

You were right, I had a pointer that was used before the call to
A_method that did not seem to be pointing correctly.

Thanx to both of you for your attention.

"Chris Theis" <Ch*********@no-spam.cern.ch> wrote in message news:<d1**********@sunnews.cern.ch>...
"marcus" <ma************@koping.net> wrote in message
news:1a*************************@posting.google.co m...
I have this class A that contains a method A_method that opens a file
and does fgets.

I also have a template class B that contains a method B_method that
takes a class A object as template type. B_method then uses this A
object to call A_method.

here is a snippet (pseudo)

In class A.cpp:
===============
B <A> myVar;

// method that uses method of template class
A::someMethod(){
myVar.B_method(this);
.
.
}

// method to be called from template class
A::A_method(char *fileName){
char iLine[200];
int meshCount = 0;

FILE *stream = fopen(fileName, "r");
//geometryData = NULL;
if(stream != NULL){
// loop through parsing every line in the file
while (fgets(iLine, 200, stream) != NULL){
.
.
}
}
}

In class B.h:
=============
B<TAG>::B_method(TAG *A_object)
{
.
.
A_object->A_method(fileName)
}

The 1st method that is invoked above is A::someMethod
The problem is that when running the application the fgets makes the
application crash (the _cnt component has the value -1). When
debugging the application though everything works fine.


Code that exhibits such behavior is very likely to cause some undefined
behavior in previous sections before your program breaks down. Most probably
the problem is not fgets() but might be found before. Use your debugger to
break before fgets is executed and check the variables & pointers that are
around.

HTH
Chris

Jul 23 '05 #5

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

Similar topics

3
by: Simon Burton | last post by:
Hi, I'm after a no-op command, so that i can redirect logging commands in performance critical code. Something like this: def log(*args): print args def null_log(*args): pass if not...
2
by: Bonj | last post by:
When building a windows forms application in C#, I notice that you get two different folders for different builds, debug and release. But when building a web application there is only one,...
10
by: Scott | last post by:
I have a simple asp.net app which works fine in debug mode, but crashes on the following line when I run it on the production server: Dim dt As DataTable I have tried the following variations...
3
by: John C Kirk | last post by:
I've come across an odd situation, where doing a floating point division produces different results for the same numbers. Basically, there are 4 ways to run this application: A) Debug build,...
7
by: =?Utf-8?B?R3JpZ3M=?= | last post by:
Hello, After getting some posts on forums.microsoft.com but no solution I was asked to post over here. Hopefully someone here can help with my problem. I have a Windows Forms application...
8
by: ramhog | last post by:
I have a class which implements several interfaces. One of them I would like to have implemented only if it is a debug build. Is there a way to do this? Thanks.
0
by: Kim | last post by:
Im generally new to ASP, so bear with me. This is not ASP (dot) NET. I have a query which gives results when doing the it directly, but none (maybe) when done in asp. "Maybe" because I can not...
2
by: kailashchandra | last post by:
<html> <head> <title>PHP Test</title> </head> <body> <?php echo $_SERVER; ?> </body> </html>
1
by: yawnmoth | last post by:
<?php $content = ' <a> <d> <b> <c/><c/> </b> </d> <b> <c/><c/><c/>
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.