473,651 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2508
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*******@gmai l.com> wrote in message
news:11******** **************@ h76g2000cwa.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** **************@ h76g2000cwa.goo glegroups.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*******@gmai l.com> wrote in message
news:11******** **************@ h76g2000cwa.goo glegroups.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
1352
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 module allows trapping the signal, it does not offer a truly portable way of respecting the termination request. As far as I can see, this issue has been a topic of conversation for years, but I don't see that it has ever been solved: ...
2
2083
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 communicate between the threads. The problem is that the program infrequently terminates with no indication of why it terminated.
2
10433
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 with gcc 3.4.2-mingw. I have tried the TCPL Spec.Ed. example of just adding std::bad_exception to the exception specification of a function promising to throw an int, but throwing a string-literal (effectively a pointer). I call that from main...
1
30248
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 <joined_table> Explanation: A syntax error in the SQL statement was detected at the specified token following the text "<text>". The "<text>" field indicates the 20 characters of the SQL statement that preceded the token
35
2566
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 information somehow be used as a substitute for 0-termination of strings? Felix
2
1529
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 a C# class and instanciate an instance of this class within a new AppDomain. Here are my question: Am I correct to assume that I will be able to handle cases where the library
32
4399
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 urllib2, urlparse, robotparser and some other modules in the battery pack. One day my app failed with an urllib2.HTTPError. So I catch that. But then I get a urllib2.URLError, so I catch that too. The next day, it encounters a urllib2.HTTPError, then...
669
25855
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
9
6885
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 Enter a number : 30 More numbers (y/n)? n
0
1419
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 ) Termination value = value of 16 days of march + value for 8 months ( april to nov) + value of 15 days of Dec
0
8367
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8811
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...
1
8467
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
8589
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...
1
6160
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
5619
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
4145
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...
1
2703
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
2
1591
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.