HDTenEightyP/NetNews huggingface dataset:
From: jbn@lulea.trab.se (Johan Bengtsson)
Newsgroups: comp.lang.c++
Subject: Re: How to run destructors of all objects when failure exit occurs ?
Date: 16 Nov 92 12:11:33 GMT
Organization: Telia Research AB, Aurorum 6, 951 75 Lulea, Sweden
X-Newsreader: Tin 1.1 PL4

dolgov@inpbox.inp.nsk.su (Yuri V. Dolgov) writes:
: 
:    Often I use failure program exit when some conditions are bad.
: The trouble is: I created some objects (e.g. dialog boxes, network connections
: and so on) and I want to run destructors before program exit.
: Is there exist standard technique in C++ language to solve this problem ?

Well, yes, it is called exception handling, and it is in the C++ language,
although it is not implemented by most current compilers.

_If_ you had an exception-capable compiler, you might say

class DieSucker { }; // Empty class used to represent total program failure.
throw DieSucker;	// causes unconditional branch out of the program,
			// unless a statement "catch( DieSucker )" is
			// somewhere in the call chain.

Destructors will be called for all stack-based (automatic) variables.
You should represent the program resources as such automatic variables.

Anyway, today you will need to take care of the destruction business
yourself, by creating a special Resource class, from which the other
resource classes inherit.  The constructor of class Resource registers
the Resource in a global list.  Resource::cleanup() automatically calls
the destructors of the registered objects.

More details can be found in my paper "C++, Without Exceptions"
(FTP info below).  Section 3.6 discusses the creation of a Resource
class, which you should be able to use for your purpose, with small
changes (make the Resource::cleanup() method puclic, so you can
call it before calling exit()).

==== FTP info ======================================================
I have made my paper "C++, without exceptions" available for anonymous FTP.
Mats Henricsson at Ellemtel Utvecklings AB has helped me with this.
Thanks Mats!

The document was written using FrameMaker, but has been saved in Postscript
and compressed. It can be accessed by anonymous ftp from the server:
   euagate.eua.ericsson.se   (Internet Address: 134.138.134.16)
It is in the directory:
   ~ftp/pub/eua/c++
The file is ~36k large and its name is:
   Except.ps.Z
=====================================================================

-- 
--------------------------------------------------------------------------
| Johan Bengtsson, Telia Research AB, Aurorum 6, S-951 75 Lulea, Sweden  |
| Johan.Bengtsson@lulea.trab.se; Voice:(+46)92075471; Fax:(+46)92075490  |
--------------------------------------------------------------------------
From: aze@first.gmd.de (Andre' Zehl)
Newsgroups: comp.lang.c++
Subject: watching function-calls
Keywords: function calls
Date: 20 Nov 92 15:00:57 GMT
Distribution: comp

I want to monitor function calls - see which functions are called in 
my prog and what parameters they have. I have a simple parser, that can
parse header-files and I thus could modify class-definitions in headers .
I can figure out the parameters and the function names - but what do
I have to do to watch the actual calling of the functions ?

Is there an obvious solution, that I don't see ? Is this impossible 
without editing the implementation files ? 

Any hint, pointer to literature, etc. is highly welcome.
Please reply by e-mail!

--
Andre'_________________________________________________________________________
	 			      crusoe@cs.tu-berlin.de [aze@first.gmd.de]
Newsgroups: cvnet.c++,comp.lang.c++
From: mpk9172@ultb.isc.rit.edu (M.P. Kirby)
Subject: Finding memory leaks
Originator: mpk9172@ultb
Keywords: OOP,memory leaks
Organization: Rochester Institute of Technology
Date: Fri, 20 Nov 1992 19:18:28 GMT

In C I used to use a memory leak finder that would help me find
my memory leaks.  I basically created a #define for malloc that redefined
it to do:

#define malloc(size) (my_malloc(__FILE__,__LINE__,size)

This allowed me to maintain a list of all my memory allocations.  I would
redefine free to be my_free to mark the element on the list as "freed."
This allowed me to check to see what memory was outstanding at 
different points in the program. (and at the end).  I would then be
able to find out that a block of 300 k was allocated in file "stuff.c" at
line 53.  This proved useful during the debuging stage.

I would like to do the same kind of thing in C++.  Unfortunately, it
seems that new is not as easy to #define over as malloc.  I thought
(briefly) that I could do something like #define new new(__LINE__,__FILE__) 
 and then overload the new operator, but this causes a recursive macro.

Creating something that calls my_new doesn't work either.  Apparently the
sytanx surround the new operator is special.

Is there anyway to do what I am trying to accomplish?  

Actually, What I would really want is a stack dump at every memory allocation.
This way I would not only know that a block was allocated at a certain
line number and in a file, but it was ordered by these people.  But I'm
willing to take the easy way out.  Just knowing that I have a memory
leak and where it is occuring is good enough.


Mike Kirby
mpk9172@ultb.isc.rit.edu
Rochester Institute of Technology
Newsgroups: comp.lang.c++
From: sailer@hpuerca.atl.hp.com (Lee Sailer)
Subject: Seeking fine code examples
Date: Sun, 22 Nov 1992 20:39:32 GMT
Organization: Hewlett-Packard NARC Atlanta
X-Newsreader: Tin 1.1.3 PL5

I am looking for some good examples of real programs written in C++
that demonstrate some coding or design style very well.  That is, I
am more interested in code that implements beautiful C++ than I am
interested in what the code does.

If you know of such code, please post here or let me know by email.
I can FTP it to get it here to my machine.

Thanks.

lee
-- 
Lee Sailer
Newsgroups: comp.lang.c++
From: pete@borland.com (Pete Becker)
Subject: Re: Just what is so great about streams?
Originator: pete@genghis.borland.com
Organization: Borland International
Date: Tue, 17 Nov 1992 17:04:55 GMT

In article <mg.721969238@tyrolia> mg@tyrolia (Michael Golan) writes:
>Hi!
>
>Any good reason why
>  cout << fmt("%5d %5d\n") << x << y ;
>or even
>  cout("%5d,%5d\n") << x << y ;
>do not exist?
>
>  cout << dec(5) << x  << " " << dec(5) << y << "\n" ;
>
>is not type-safer, is it? the formatting is ignored if x,y have non-int
>type, just like %5d would be.
>

	Such a construct quickly becomes meaningless in the presence of
user-defined inserters:

	class complex
	{
	public:
	double real, imag;
	};

	ostream& operator << ( ostream& os, complex c )
	{
	return os << '(' << c.real << ',' << c.imag;
	}

Now, what should the library do with this?

	complex c1, c2;
	cout << fmt( "%f %f %5d" ) << c1 << c2 << 3;

Should it apply only one specifier for each inserter?  Keeping in mind, of
course, that each inserter for a complex is in reality two inserters for a
double...
	-- Pete

Newsgroups: comp.lang.c++,comp.std.c++
From: xjzhu@math.uwaterloo.ca (Xiaojun Zhu)
Subject: "Invalid" argument(s) in template class declaration, how to realize?
Keywords: template, argument
Organization: University of Waterloo
Date: Fri, 20 Nov 1992 00:14:46 GMT

Q: When designing a template class, how to make sure that its argument
   can only be certain classes or certain predefined types?

Another words, can we build a template class such that it only accepts 
certain types as its arguments, while for others it will generate an
error message such as:

   This type is not supported by this template.

if you attempt to use them as the argument.

To give you an example( hopefully you will think it's reasonable! )

template<class T>
class Expect_Numerical_In_Nature
{
   T Nian;
public:
   // ...
};

and suppose that we also have:

	class Not_Numerical_In_Nature;

then we will expect the following declaration:

	Expect_Numberical_In_Nature<Not_Numerical_In_Nature> Not_Valid;

generate an error message.

How do we provide such a mechanism?

P.S. While I am writing this down, I feel this is probably a hard question,
  because, I think, the template of C++ doesn't provide such property?
(Well, just guess, don't get offended if it actually does.)  How hard
will be a work around? 

--------------------------------------------------------------
   A template version of my signature class is under repair.
Symptom: It dies without a warning if I use certain class 
         as an argument.
         
                                       xjzhu@math.uwaterloo.ca
--------------------------------------------------------------
Newsgroups: cvnet.c++,comp.lang.c++
From: rvloon@cv.ruu.nl (Ronald van Loon)
Subject: Real life problem: what is the proper way of subclassing this ?
Originator: rvloon@triton.cv.ruu.nl
Date: Mon, 16 Nov 1992 16:08:06 GMT
Organization: University of Utrecht, 3D Computer Vision Research Group
Keywords: OOP,superclass-subclass relationships, real life problem

The problem is the following:

consider a basic graphics class, called 'point3d' encapsulating the concept of
a 3D-point in a coordinate-system. Mind you, the coordinate system is
important, every point has one. A number of operations are defined on those
points, like multiplication (inproduct), adding (translation) etc. etc.
Everytime two points are incompatible, ie. are in different coordinatesystem,
one of the two is forced in the coordinatesystem by a coordinate
transformation.

Now, for efficiency reasons, the check whether points are in the same
coordinatesystem needs to be removed, as it turns out that most of the time
points are already in the same coordinatesystem, hence testing is not needed.

Two approaches can now be taken:

1. The original 3-dimensional point in coordinatesystem concept is a special
   case of a normal 3-dimensional point:

   class point_3d
   {
    // baseclass

    ... operations ...

   };

   class point_3d_with_coordinate_system
	: public point_3d
   {
     // subclass
   };

   additional advantage:

   all code for point_3d_with_coordinate_system is very straightforward:

   point_3d_wc::function(point_3d& point2)

   if (point1 not in same coordinate system as point 2)
     force point2 in same coordinate system as point1

   execute equivalent code in baseclass (as coordinate systems are the same)


2. The 3 dimensional point without checks for coordinate systems is a special
   case of the normal case.

   class point_3d_with_coordinate_system
   {
     // different baseclass
   };

   class point_3d_with_no_coordinate_system_check
	: public point_3d_with_coordinate_system

   obvious disadvantage:

   all code from the base-class needs to be duplicated (as the code from
   the baseclass contains the check for coordinate systems).

Any and all opinions from the net appreciated

-- 
+--- Ronald van Loon ---+ 
|  (rvloon@cv.ruu.nl)   | 
|  3DCV Group, Utrecht  |
+--- The Netherlands ---+ This part of .signature intentionally left blank.
From: srlncnc@gopher.dosli.govt.nz (Chris Crook)
Newsgroups: comp.lang.c++
Subject: Using delete with arrays - help please!
Date: 16 Nov 92 02:38:52 GMT
Organization: Department of Survey and Land Information, New Zealand

Hi

Can you clear up a bit of confusion I have about the use of delete with
arrays.

My understanding is that I can allocate an array of class instances using
the syntax

   MyClass arrayOfInstances = new MyClass[arraySize];

and that when I want to delete it I use

   delete [] arrayOfInstances

I have written a small test program to let me know when the constructors
and destructors are called, and this all seems to work.  If I omit the
[] in the delete statement then the destructor is called only once.  It
also leads to a "Null pointer assignment" error from Borland C++ when the
program ends, presumably because the memory allocation has got messed
up.

What I am puzzled about is the wide use of arrays of characters in
the Borland code examples in which the arrays are allocated as

   char *aBuffer = new char[bufferSize];

   delete aBuffer;

Can you tell me why this works? Why doesn't it need the [] after the
delete operator? Is it because char is an internal type?


My apologies if this is an obvious question - I am still waiting for our
library to get the C++ programming manual, so I do not have a definitive
C++ reference available.

Thanks in advance for any help

Chris Crook

P.S: below is the test program I was working with
=====================================================================

// Just testing constructors and destructors on an array

#include <iostream.h>


class MyClass {
   int instance;         // Number of current instance
   static int count;     // counter of instances created
public:
   MyClass();            // Default constructor and destructor
   ~MyClass();
   };

int MyClass::count = 0;

MyClass::MyClass() {
   instance = ++count;
   cout << "MyClass instance " << instance << " created\n";
   }

MyClass::~MyClass() {
   cout << "MyClass instance " << instance << " deleted\n";
   }

// Test program includes both automatic and dynamic allocation.

int main( int argc, char *argv[] ) {
   MyClass oneArray[5];
   MyClass *anArray = new MyClass[6];
   // delete [] anArray;
   delete anArray;
   return 0;
   }
Newsgroups: comp.lang.c++,comp.object
From: rmartin@thor.Rational.COM (Bob Martin)
Subject: Re: How do you sell OOP to management?
Organization: Rational
Date: Fri, 20 Nov 1992 18:33:12 GMT

You hit on some important points.  The prospect of switching a
development environment from procedural to OO will involve risk and
expense.  The risk and expense will be immediate, and will involve
cash, time and point failures of the method.  The benefits, though
real to those of use who use OO techniques, are difficult to justify.

About 15 years ago I had a similar problem trying to convert an
assembly language shop to use C.  The issues were similar.  Switching
to C meant cash outlays for compilers and tools and training.  Lost
momentum due to learning curve.  And increased errors due to
inexperience.  Moreover there was simply the risk of the unknown.
Many engineers felt that C would generate programs that were to big
and slow to work in our environment.

These attitudes changed gradually over time.  As those few of us who
used C began to repot successes in our projects.  More and more
engineers began to feel better about C and take the plunge and try it
on a simple project.  

Eventually the time came when more than half the engineers were using
C, and the difference in productivity and quality between the two
populations was very evident.  At this point the company hired outside
consultants to come in and teach C to the rest of the engineers.  The
company has been using C ever since. 

This process took about four years!  


--
Robert Martin                        Training courses offered in:
R. C. M. Consulting                       Object Oriented Analysis
2080 Cranbrook Rd.                        Object Oriented Design
Green Oaks, Il 60048 (708) 918-1004       C++
Newsgroups: comp.lang.c++
From: mg@elan (Michael Golan)
Subject: template member func:  class X { template<class T> f(T& x) {...}}
Organization: Princeton University, Dept. of Computer Science
Date: 21 Nov 92 01:47:00 GMT

Why isnt this allowed?

class File {
	binwrite(void *buf,size_t sz) {...} // write buf of length sz 
public:
	template<class T> write(T& buf) { binwrite(buf,sizeof(T)); }
};

of course I can do

template<class T> write(File& f,T& buf) { f.binwrite(buf,sizeof(T)); }

But it isn't quite the same thing - write becomes global!

 Michael Golan
 mg@princeton.edu
Newsgroups: comp.lang.c++
From: pete@borland.com (Pete Becker)
Subject: Re: Idempotent header file proposal
Originator: pete@genghis.borland.com
Organization: Borland International
Date: Tue, 24 Nov 1992 03:02:26 GMT

In article <722547379snx@trmphrst.demon.co.uk> nikki@trmphrst.demon.co.uk writes:
>In article <1992Nov20.200435.18239@microsoft.com> jimad@microsoft.com (Jim Adcock) writes:
>> Ultimately we will begin to see more and more C++
>> development environments that not only offer precompiled headers, but
>> incremental compile/link support as well.
>It is unfortunate that most of the current compilers which have
>precompiled headers have such restrictions on their use, and such arcane 
>command lines to use them, that they introduce problems, rather than 
>solving them.
>
>For example, all the compilers I have seen with this feature insist that 
>all modules that use the precompiled headers include the same headers, in 
>exactly the same order. This encourages users to include ALL their headers
>in all their modules. This introduces lots of unnecessary dependencies, 
>and means a very slow compile cycle when the code is moved to another 
>compiler, without precompiled headers.
>

	BC permits you to include headers in whatever order you want, and the
"arcane" command line is -H.  There are additional things you can do to tune
the performance, such as using all the same headers in the same order in 
several different compilation units, but that is not required.
	-- Pete
Newsgroups: comp.lang.c++
From: mcgrant@rascals.stanford.edu (Michael C. Grant)
Subject: Re: template member func:  class X { template<class T> f(T& x) {...}}
Organization: Information Systems Laboratory, Stanford University
Date: 22 Nov 92 17:51:56

In article <1992Nov22.210314.18135@murdoch.acc.Virginia.EDU>
gs4t@virginia.edu (Gnanasekaran Swaminathan) writes:

   mg@elan (Michael Golan) writes:
   : Why isnt this allowed?
   : 
   : class File {
   : 	binwrite(void *buf,size_t sz) {...} // write buf of length sz 
   : public:
   : 	template<class T> write(T& buf) { binwrite(buf,sizeof(T)); }
   : };
   Because there is an alternate way to do the same.
   template <class T>
   class File {
       void binwrite(void* buf, int sz) {}
   public:
       void write(T* b) { binwrite(b, sizeof(T)); }
   };
   main()
   {
       File<int> f;
       int i = 0;
       f.write(i);
   }

That ISN'T the same thing. What if I wanted to do this:

main() {
  File* f;
  int i = 10;
  double j = 4;
  ...
  f.write(i);
  f.write(j);
}

The benefit to allowing this is that write(T& buf) could then be inlined
for every data type. I believe a superior example is this:

template <class T>
class Matrix {
// just guess how it's defined!
public:
  template <T (*func)(const T&)> Matrix& apply( void ) {
       for ( register int i = 0; i < totalLength ; i++ )
           data[i] = (*func)(data[i]);
       return *this;
  }
  Matrix& apply( T (*func)(const T&) ) { ...non-templated form... }
  Matrix operator-( void ) const { return Matrix(*this).apply<&operator->(); }
  // questionable syntax?
}

Why is this useful? Because some computers have inlinable code for some
of the standard floating-point functions such as fabs(), sqrt(), etc. So,
I would hope and expect that a compiler could take

main() {
  Matrix<double> m(50,50);
  ...
  m.apply<&fabs>();
  m.apply<&sqrt>();
}

and properly inline the code. (alternatively, I could have written an
inlined function myself...) I've also wanted to template conversions
from one Matrix type to another, i.e.

template <class T,class U>
Matrix<T>::Matrix( const Matrix<U>& m ) { ... }

and let compiler errors and the like reject conversions that aren't
automatic.

Mike

--
-----
"Long hair, short hair--what's the difference once the head's blowed off?" (?)
Newsgroups: comp.lang.c++
From: dgreen@sti.com (Dan R. Greening)
Subject: Re: Proposal - enhancement for switch statement.
Organization: Software Transformation, Inc.
Date: Mon, 16 Nov 1992 03:32:23 GMT

mcgrant@rascals.stanford.edu (Michael C. Grant) wrote:
>In article <1992Nov15.190830.11622@cssc-syd.tansu.com.au>
>pete@cssc-syd.tansu.com.au (Peter Alexander Merel) writes:
>> [switch on any type using == proposal]
>>  Any chance?
>
>I doubt it... Even before C++ came along, switch statements could not
>handle floats, strings, structures, etc. Sure, a switch statement could
>be turned into a set of if-then-else statements, but it isn't because
>it usually is best turned into a jump table.

Smart compilers should put it into a series of jump tables and do binary
search to identify the correct jump table.

The obvious rhetorical question is "why not require SwitchType to have
a well-ordering relation using operator< and operator==?".  They you could
at least do the binary search part instead of a sequence of "=="
operations.

But the rhetoric is just that:  I'd prefer to keep it simple, and leave
switch alone.

The reason is pretty simple: you as the programmer know your data much
better than the compiler.  If you are going to use expensive operations,
like a series of categorizing "==" operator calls, it seems like you 
should tailor your "switch" to the data.  The compiler can't do that.
-- 
____
\  /Dan Greening    Software Transformation   1601 Saratoga-Sunnyvale Rd, #100
 \/dgreen@sti.com   (408) 973-8081 x313       Cupertino, CA 95014
Newsgroups: comp.lang.c++
From: brianm@cc.gatech.edu (Brian N. Miller)
Subject: g++ ofstream
Organization: Georgia Tech College of Computing
Date: Thu, 19 Nov 1992 17:30:58 GMT

What flags should i check or what method shall i call
to determine if a once opened g++ ofstream has since been closed?
From: je@unix.brighton.ac.uk (John English)
Newsgroups: comp.lang.c++,bnr.lang.c++
Subject: Re: Criticisms wanted
Date: 16 Nov 92 10:19:48 GMT
Organization: University of Brighton, UK

dan@BofA.com (Dan Brockman) writes:
: In article <DECHC00.92Nov6072628@tohi.DMI.USherb.Ca> dechc00@tohi.DMI.USherb.Ca (CHRISTIAN DECHAMPLAIN) writes:
: >
: >I think that people that don't want to code in C++ are just afraid.
: > [... etc ...]
: 
: [... etc ...]
: Also consider...  Do people choose not to code in COBOL because they
: are afraid of it?

Well, yes... frankly, Cobol TERRIFIES me!
-- 
-------------------------------------------------------------------------------
John English			| "Yes, understanding today's complex world of
Dept. of Computing		|  the future IS a little like having bees live
University of Brighton		|  in your head... but, there they are..."
Janet: je @ unix.brighton.ac.uk	| "People who live in windowed environments
Fax:   0273 642405		|  shouldn't cast pointers"
-------------------------------------------------------------------------------
From: bachmann@romulus.rutgers.edu (Dan Bachmann)
Newsgroups: comp.lang.c++
Subject: C++ reference via FTP please
Keywords: C++ reference
Date: 21 Nov 92 19:51:01 GMT
Organization: Rutgers Univ., New Brunswick, N.J.



could someone please send me the address/directory of an FTP site that
has a mini-C++ reference. There must be something available out there.

Also, our system is not untaring files... so it would be a plus if
it's not .tar'd.

		thanks much!
			- Dan
Newsgroups: comp.lang.c++
From: brianm@cc.gatech.edu (Brian N. Miller)
Subject: Re: self-reproducing C++ program
Reply-To: brianm@cc.gatech.edu (Brian N. Miller)
Organization: College of Computing, Georgia Institute of Technology
Date: Tue, 17 Nov 1992 14:49:39 GMT

In article <1919@alcbel.be> ldup@ta7s49.alcbel.be (Luc Duponcheel) writes:

> <<';'<<

This won't work, because character constants are converted to ints.
This will output the ascii decimal equivalent of ';', right?
Newsgroups: comp.lang.c++
From: mazz@mars (Richard Mazzaferri)
Subject: Re: self-reproducing C++ program
Organization: Uni of Newcastle, Australia
Date: Thu, 19 Nov 1992 04:38:44 GMT

brianm@cc.gatech.edu (Brian N. Miller) writes:

>In article <1919@alcbel.be> ldup@ta7s49.alcbel.be (Luc Duponcheel) writes:

>> <<';'<<

>This won't work, because character constants are converted to ints.
>This will output the ascii decimal equivalent of ';', right?

No, <stream.h> had this behaviour, but <iostream.h> outputs chars as chars.

    Mazz.
--
Richard Mazzaferri        Ph.D. student          Uni. of Newcastle 
  Ph (049) 216254   mazz@faceng.newcastle.edu.au     Australia.
Newsgroups: comp.lang.c++