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

Unexpected Termination

KS

I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?

I would really appreciate it if you would take a look at the source. I
have uploaded the complete source file at:
http://www.grex.org/~kpp/gamultiknapsack.cpp
(You will need the orlib1.txt in the same directory to execute this
file).

Thank you.

KS

Jun 9 '06 #1
7 2494
KS
> (You will need the orlib1.txt in the same directory to execute this
file).


The orlib1.txt file is uploaded on the same server:
http://www.grex.org/~kpp/orlib1.txt

Jun 9 '06 #2
Hi

KS wrote:
I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?


There are so many known bugs that can cause this problem that I am not going
to list them here.
You should try using a debugger (with a debug build) to find out which one
you are affected by.

Markus
Jun 9 '06 #3

"KS" <kn*******@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...

I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?


Are you sure there's a problem? On my machine, when I run from the IDE, I
need to add a cin statement (or something similar) at the end of the program
to keep the window open so I can read the output. Otherwise, it finishes
the execution normally, then closes the console window before I can read
what it wrote.

If you're sure there's a problem, then use your debugger to step through and
see where something goes wrong (or at least post a minimal compilable
example which demonstrates the problem that we can look at here).

-Howard
Jun 9 '06 #4

KS wrote:
I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?
There are many ways to write buggy code. There's no way to tell which
bug you have implemented.
I would really appreciate it if you would take a look at the source. I
have uploaded the complete source file at:
http://www.grex.org/~kpp/gamultiknapsack.cpp
(You will need the orlib1.txt in the same directory to execute this
file).


ICK. I didn't really look at the code to close, but this is (some of)
what goes to STDERR when I run the executable built from your source.
a.out(3939) malloc: *** Deallocation of a pointer not malloced:
0x500520; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug
a.out(3939) malloc: *** error for object 0x500570: double free
a.out(3939) malloc: *** set a breakpoint in szone_error to debug
a.out(3939) malloc: *** Deallocation of a pointer not malloced:
0x500520; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug
a.out(3939) malloc: *** error for object 0x500570: double free
a.out(3939) malloc: *** set a breakpoint in szone_error to debug
a.out(3939) malloc: *** Deallocation of a pointer not malloced:
0x500520; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug
a.out(3939) malloc: *** error for object 0x500570: double free
a.out(3939) malloc: *** set a breakpoint in szone_error to debug
a.out(3939) malloc: *** Deallocation of a pointer not malloced:
0x500520; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug
a.out(3939) malloc: *** error for object 0x500570: double free
a.out(3939) malloc: *** set a breakpoint in szone_error to debug
a.out(3939) malloc: *** Deallocation of a pointer not malloced:
0x500520; This could be a double free(), or free() called with the
middle of an allocated block; Try setting environment variable
MallocHelp to see tools to help debug

Jun 9 '06 #5

Howard wrote:
"KS" <kn*******@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...

I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?


Are you sure there's a problem?


Oh, there are problems....
There's code like this...
class KNode
{
public:
int * knapsack;

KNode() {}
KNode( int * bla ) { knapsack = bla; }
~KNode() { delete knapsack; }
};

knapsack is unitilized if the object is default constructed, and then
its deleted in the destructor.

This is just one of the many problems with this code.

-Brian

Jun 9 '06 #6

"KS" <kn*******@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...

I have taken up C++ after about 4 years with Java and I am facing a
problem with the code that I have written. The problem is that the
execution unexpectedly terminates without any error or dump. Are there
any commonly known bugs that can cause this problem?

I would really appreciate it if you would take a look at the source. I
have uploaded the complete source file at:
http://www.grex.org/~kpp/gamultiknapsack.cpp
(You will need the orlib1.txt in the same directory to execute this
file).

Thank you.

KS


I would advise you to recode your program without using operator new at all.
Use std::vector for all arrays. In C++ you can't return an array but you can
return a std::vector.

Don't write a destructor unless you know what you're doing. KNode, for
example, will cause undefined behavior if you just copy an instance. The
pointers get deleted twice. That's because you have a destructor but no copy
constructor or assignment operator. (Look up "rule of three".) If you follow
my advice about std::vector you will not have to write any destructors.

If you insist on allocating C-style arrays, make sure you delete them with
delete [] not just plain delete. In other words:

int *p = new int[3];
delete [] p;

Using delete p; here is undefined behavior.

Cy
Jun 9 '06 #7
KS
> Oh, there are problems....

knapsack is unitilized if the object is default constructed, and then
its deleted in the destructor.

This is just one of the many problems with this code.

-Brian


Yes that was the problem. Thank you for the replies.
(The mingw-g++ produced executable just terminates without any error
message)

Jun 11 '06 #8

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

Similar topics

0
by: Alexander Staubo | last post by:
Python does not seem to clean up gracefully on SIGTERM: The exit sequence is not invoked on termination, so the atexit module cannot be used to install shutdown logic. Further, while the signal...
2
by: Jim McGrail | last post by:
Background: I am investigating a problem involving a windows .NET application that is being developed in C# with Visual Studio 2003. It is a multi-threaded application that uses MSMQ to...
2
by: Attila Feher | last post by:
Hi all, I have not done much work around exceptions; and even when I do I avoid exception specifications. But now I have to teach people about these language facilities, so I am trying them out...
1
by: Najm Hashmi | last post by:
Hi all , I am trying to create a store procedure and I get the following error: SQL0104N An unexpected token "END-OF-STATEMENT" was found following "END". Expected tokens may include: "JOIN...
35
by: Felix Kater | last post by:
The C-faq says that "The malloc/free implementation remembers the size of each block allocated and returned, so it is not necessary to remind it of the size when freeing." Could that length...
2
by: José Joye | last post by:
I have a library written in C (I do not have the source) and having some callbacks exported. It is currently not that stable and write to stdout and stderr :-(( The idea I have is to wrap it with...
32
by: Rene Pijlman | last post by:
One of the things I dislike about Java is the need to declare exceptions as part of an interface or class definition. But perhaps Java got this right... I've writen an application that uses...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Languageâ€, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
9
by: ehabaziz2001 | last post by:
I am facing that error message with no idea WHY the reason ? "Abnormal program termination" E:\programs\c_lang\iti01\tc201\ch06\ownarr01o01 Enter a number : 25 More numbers (y/n)? y...
0
by: vsankar9 | last post by:
It's an Service Contracts From CRM. I need termination amount for who's the customer is terminated . End date - 15-DEC-2007 Termination as of date - 15-MAR-2007 Rate - 1000 (monthly rate ) ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...
0
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...
0
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,...

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.