473,779 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1692
"marcus" <ma************ @koping.net> wrote in message
news:1a******** *************** **@posting.goog le.com...
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(cha r *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_metho d(TAG *A_object)
{
.
.
A_object->A_method(fileN ame)
}

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************* **********@hotm ail.com
Above views may belong only to me.
Jul 23 '05 #2

"marcus" <ma************ @koping.net> wrote in message
news:1a******** *************** **@posting.goog le.com...
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(cha r *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_metho d(TAG *A_object)
{
.
.
A_object->A_method(fileN ame)
}

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************ ***********@hot mail.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.cer n.ch>...
"marcus" <ma************ @koping.net> wrote in message
news:1a******** *************** **@posting.goog le.com...
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(cha r *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_metho d(TAG *A_object)
{
.
.
A_object->A_method(fileN ame)
}

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
1469
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 DEBUG: log = null_log
2
300
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, c:\inetpub\wwwroot\<projectname>\bin .. Am I right in thinking that whether the current build that is prevalent is dependent on what build was done most recently? Is there a magic button or way of defining a macro to "switch to release mode, build, then...
10
4897
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 which produce the same result: Dim dt As System.Data.DataTable Dim dt As DataTable = New DataTable The error message reads: System.NullReferenceException: Object reference
3
1939
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, inside the IDE B) Debug build, outside the IDE (e.g. launched from Explorer) C) Release build, inside the IDE D) Release build, outside the IDE Using methods A-C produces one result, and using method D produces a
7
3062
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 written in C# via VS 2003. It does 100% of what it should while in Debug mode (running in the debugger as well as running the .exe from File Explorer.) However, there is one thing it does not do when compiled in Release mode (running in the debugger...
8
1804
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
1501
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 get the query to output anything. sample code: set results = conn.execute("Select field1, field2, field3 from tbl") while results.EOF
2
5576
by: kailashchandra | last post by:
<html> <head> <title>PHP Test</title> </head> <body> <?php echo $_SERVER; ?> </body> </html>
1
2130
by: yawnmoth | last post by:
<?php $content = ' <a> <d> <b> <c/><c/> </b> </d> <b> <c/><c/><c/>
0
9633
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
10137
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
10074
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
9928
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
8959
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
6724
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
5373
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
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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

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.