HDTenEightyP/NetNews huggingface dataset:
From: sas@regina.aruba.UUCP (Steve Sciandra)
Newsgroups: comp.lang.c++,comp.lang.c
Subject: Re: Newbie Wants Advice on C-Programming
Date: 30 Dec 92 15:30:33 GMT
Reply-To: sas@opl.com
Followup-To: comp.lang.c++
Organization: Marcam Corporation

|> > 1) There seems to exist C, as well as C++, and possibly other variants.  What
|> >    are the differences between these?  Which should we learn first?
|> 
|> You really have to learn C before learning C++, but you might as well learn
|> C++ _programming_ directly.
|>  

I learned C++ programming as my first language ( if you don't count COBOL).
My finding was that i didn't need to know a thing about C syntax wise to
learn C++.  it turned out, however, that learning about pointers, structs,
etc, I then realized that I have learned some C in the process of learning C++.I cannot claim that I learned all the C idioms and such things that one
learns from years of C programming, but learned enough of it through C++
to read C programs and maintain them..

Another point, which supports your point, is that most people I ran across
while learning C++ already knew C and would often compare a C++ construct
to a C construct, etc.  By knowing C, one could benefit from  a understanding
of where C++ came from...
From: adk@Warren.MENTORG.COM (Ajay Kamdar)
Newsgroups: comp.lang.c++
Subject: Re: >>>>>>>>  Is it possible to use 'delete this' ?
Date: 31 Dec 1992 10:47:06 -0500
Organization: Mentor Graphics Corp. -- IC Group
NNTP-Posting-Host: ajay.warren.mentorg.com

In article <796@ulogic.UUCP> hartman@ulogic.UUCP (Richard M. Hartman) writes:
>
>Is it possible, within the definition of a class, to ensure that
>the object may only be successfully created by "new" and not
>by a simple declaration?
>
>e.g.
>
>	Object *p = new Object;		// ok
>	Object O;					// fails
>
>

Yes, this is possible. Make the destructor of the class private. That
will prevent users of the class from creating objects on the stack
(attempts to create such an object on the stack will result in a compile
time error.) A side effect of making the destructor private is that the
object cannot be deleted directly; a member function to perform delete
takes care of that problem.

Example:

class A {
public:
	A() {}
	void free() {delete this;} // delete the object
private:
	~A() {} // will prevent A objects from being created on the stack
};

int main()
{
	A a1;		// compile time error
	A *a2 = new A;	// ok
	delete a2;	// compile time error
	a2->free();	// ok. deletes object.
	return 0;
}


- Ajay

-- 
I speak for none but myself.

Ajay Kamdar                               Email : ajay_kamdar@mentorg.com
Mentor Graphics, IC Group (Warren, NJ)    Phone : (908) 580-0102
Newsgroups: comp.lang.c++
From: cflatter@nrao.edu (Chris Flatters)
Subject: Re: template disappointments ... (suggestions?
Reply-To: cflatter@nrao.edu
Organization: NRAO
Date: Tue, 29 Dec 1992 20:44:31 GMT

In article 92Dec29133556@muse.cv.nrao.edu, dschieb@muse.cv.nrao.edu (Darrell Schiebel) writes:
>	(1) The inability to derive templated classes from a non-templated 
>	    base class of the same name:
>		class typeinfo {};
>		template<class t> class typeinfo : public typeinfo {};

This is according to the ARM:

	A class template name must be unique in the program and may not
	be declared to refer to any other template, class, function,
	object, value, or type in the same scope.
							[p343]
>
>	(2) but worse than this minor item, it seems as though it is 
>	    impossible to compose templates from templates:
>		template<class t> class vector {};
>		template<class t> class list {};
>
>		list<vector<int>> list_vec_int;

Put a space between the two closing angle brackets: ">>" lexes as the right-shift
operator; "> >" lexes as two consecutive closing angle brackets.

	Chris Flatters
	cflatter@nrao.edu
From: mccauleyba@vax1.bham.ac.uk (Brian McCauley)
Newsgroups: comp.lang.c++
Subject: Re: Sizeof and Virtual functions
Date: 24 Dec 92 13:21:21 GMT
Organization: University of Birmingham
NNTP-Posting-Host: vax1.bham.ac.uk

In article <1992Dec24.061254.9763@nuscc.nus.sg>, suresh@papaya.iss.nus.sg (Suresh Thennarangam - Research Scholar) writes:
> One of the things that distinguishes virtual functions from other
> normal member functions of a class is that some compilers that I
> know of, store an extra pointer that is  probably used to index 
> a vector table. This is done to facilitate late binding 
> at run-time depending on the type of the object being pointed to
> rather than the type of the object pointer as opposed to normal
> member functions calls which are bound at compile time. 
> 
> Is this an implementation-specific issue only ?  
Ish.

> 
> A C++ programmer should  not have to know of these ugly little pointers
> lurking around in his structures. These monsters add 4 bytes each
> (on a 32 bit machine) to your structure; sizeof no longer tells the 
> truth and seemingly innocent  actions like fwrite'ing such structures 
> to  a file can quickly assume rather pernicious connotations. 
> 
> If I write classes with virtual functions to interpret and save 
> file formats like XWD, TIFF, GIF , etc and innocently use sizeof() 
> to calculate the size and write to a file I will be writing along 
> addresses in my machines data area. Obviously, no one will be able
> to read those files either. Of course an experienced C++ programmer
> would know how work around this problem  but this just an illustration. 
> 
> Isn't  there a better way to implement virtual functions ? 
No. The only other way would be to include the type information in the pointer
itself so all pointers to objects of classes with virtual functions would
become bigger. This would also mean that if a pointer were converted to void*
and back it would loose it's type information. (I'm not sure if a compiler
with this property would be conforming but it would certainly be unpopular).

Another solution would be to adjust the action of the `sizeof' and `(void*)'
operators to refer to the object excluding its type indicator but
this would break any code that used `malloc'.

> Isn't the current implementation a clever hack at best ?
Possibly but the only alternative would be a clumsy hack.

It is better to have `sizeof' and interconversion to `void*' do what
they do now rather than try to hide the type information outside of the
object.

Almost any use of void* and sizeof is implementation dependant, they are
really part of C and C++ programmers should avoid them whenever possible.  
-- 
    \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
 .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
.__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
.  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
 # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
Newsgroups: comp.lang.c++
Subject: Re: Is it possible to use 'delete this' ?
From: robertd@kauri.vuw.ac.nz (Robert Davies)
Date: Tue, 29 Dec 1992 02:11:02 GMT
Organization: Victoria University of Wellington

rmartin@thor.Rational.COM (Bob Martin) writes:
>robertd@kauri.vuw.ac.nz (Robert Davies) writes:
>|rmartin@thor.Rational.COM (Bob Martin) writes:
..... stuff about "delete this".

The problem I had with Bob's first reply was that he didn't answer the
question: is "delete this" legal.

I would also like to know the answer. It seems to work on all the compilers
I have access to and I understand that Bjarne uses it. So I guess it is legal,
but it would be nice to have a reference - or is it something the standards
committee should explicitly include in the standard.

I think Bob's reply would have been much more helpful if it had started out
with "yes", "no", or "not clear".

Then it would be appropriate to give a warning. Incidentally, is the warning
about is causing difficulty to some compilers just a "gut feeling" or are
there specific examples?

Bob's warning about "delete this" seems to apply to any use of "delete" by
an entity that didn't do the corresponding "new". Otherwise there is always
the risk that the "delete" will be applied to something not created by
"new". Is this another safe programming rule?

Robert
Newsgroups: comp.lang.c++
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Give me safe C++
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Date: Mon, 21 Dec 1992 23:24:17 GMT

In article <24437@alice.att.com> ark@alice.UUCP () writes:
>In article <1992Dec17.192301.23525@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
>
>> 	Next, I feel NO language has addressed the concept
>> of coroutines (except possibly Simula?).
>
>Well, there's the C++ task package.

	Which one? (But tasks aren't coroutines anyhow. I think
	objects themselves come as close as I've seen in C++).

>
>More generally, coroutines require some kind of support for
>multiple stacks, which can be a tricky problem in the absence
>of garbage collection.

	Or in a machine that uses a stack to implement
activation records. But if the activation records are placed
in the heap and threaded togther with pointers the problem
disappears.

>  One would therefore expect to find
>coroutine support in at least some languages that have
>garbage collectors, and indeed there is: Icon and Scheme
>come to mind, as well as local extensions in some implementations
>of ML.
	
	Ah, I shall have to look up how its done there sometime.
Coroutines are useful for problems which are not block
structured but have non-overlapping scopes. Subroutines
really hamper proper expression of the solution then.
A classic case of control inversion where subroutines
are used, but coroutines are more correct,
can be seen by comparing the COBOL and PL/1 sort facilities.

Another example might be in a parser/lexer where you want
to have the lexer say 'puttoken' and the parser say 'gettoken',
and have these calls bound together. I guess you
can emulate this with objects, I wonder if there
is a standard idiom?


-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
Newsgroups: comp.lang.c++
From: jrichard@cs.ulowell.edu (John 'MacGyver' Richardson)
Subject: help with virtual functions
Organization: University of Massachusetts at Lowell Computer Science
Date: Tue, 29 Dec 1992 17:25:30 GMT


I'm trying to use classes with virtual function in a shared memory array.
After reading Coplien's "Advanced C++" (p. 269) and learning that pointers
would be a problem, I think I'm going to have to go back to C (or at least
C++ without virtual functions).  

My application has a database filled with objects, all derived from the
same class.

I've thought of a few workarounds for this problem.

	o Move the objects outside of the shared memory and keep pointers
	  to the shared memory an object needs.  This involves keeping a
          distinct tag field so each process can determine what type of
	  object it should create to point to the shared memory.  Of course,
	  new processes will have to switch() on the tag to create the
	  correct object for each entry in the array.

	o Keep objects in the shared memory with a tag field to determine
	  sub-object type (types that would have been derived).  This
	  looses the biggest advantage of C++ though and we're back to the
	  switch statement!

	o Make one process handle everything.  Sounds easy, but IO is painful
          I.E. Trying to insure that one accesser doesn't tie up the 
          database by repeated IO requests or one large request is hard to do.


I noticed some talk earlier about saving arrays of classes and such and 
along the lines someone mentioned that a better C++ programmer would have
a workaround for these "virtual" problems.  Are there any??  If you know of 
any, can you mail it off to me? 

			Thanks,

			John Richardson
			jrichard@cs.ulowell.edu
Newsgroups: comp.lang.c++
From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
Subject: Re: Testing a pointer??
Organization: MAXTAL P/L C/- University Computing Centre, Sydney
Date: Wed, 23 Dec 1992 15:09:15 GMT

In article <1h5p6eINNdva@fido.asd.sgi.com> davep@paladin.corp.sgi.com (David Packer) writes:
>
>Hey,
>
>If I have a linked-list, called llist...and I want to test it
>to see if it exists. i.e. I only want to create it if needed..
>
>How do I test to see if it exists..
>
>i.e.
>
>if(!llist) { objList = new llist; }
>
>this doesn't seem to work for me??

	Not surpising, you cant make up your mind if llist is a type
of an object or what :-)

	class List { ...
	List *lp=0;
	...
	if(lp==0) lp = new List; // lp is created now if it wasnt before   
	assert(lp); 
	// lp now exists

-- 
;----------------------------------------------------------------------
        JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
	Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
From: bright@nazgul.UUCP (Walter Bright)
Newsgroups: comp.lang.c++
Subject: Re: Zortech C++ v3.1
Date: 26 Dec 92 19:23:26 GMT
Reply-To: bright@nazgul.UUCP (Walter Bright)
Distribution: usa
Organization: Zortech, Seattle

In article <1had12INNt5@news.aero.org> jordan@aero.org (Larry M. Jordan) writes:
/In article <1535@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes:
/>In article <1garn0INN7fq@news.aero.org> jordan@aero.org (Larry M. Jordan) writes:
/>/Just got an upgrade announcement in the mail for Zortech C++ v3.1.
/>/[3] Does the debugger support AT&T version 3.0? 
/>	I'm not sure what you mean here.
/Does the debugger 'understand' templates, for example? (I hope!)

Not at a sophisticated level. There is certainly room for improvement.
One problem I have never solved is that the compiler is usually the first
to support a new feature or platform, and it takes a while for the rest
of the tools to catch up.
Newsgroups: comp.lang.c++,alt.books.technical,misc.books.technical
From: earle@elroy.jpl.nasa.gov (Greg Earle - Gainfully Unemployed)
Subject: C++ Answer Book - new revision? (Was: "Re: Why is the ARM hardbound?")
Followup-To: comp.lang.c++
Keywords: ARM  Stroustrup
Organization: Gainfully unemployed
Date: Sun, 3 Jan 1993 11:13:17 GMT

In article <1993Jan1.023824.20559@dumbcat.sf.ca.us> marc@dumbcat.sf.ca.us (Marco S Hyman) writes:
>>Also, I think I saw a (green colored) "C++ Answer Book" - did I, or were my
>>eyes deceiving me?  If so, does it apply to the first edition or to the
>>second? 
>
>The Green (softcover) is 
>
>	The C++ Answer Book
>	Tony L. Hansen
>	Addison-Wesley 1990
>	ISBN 0-201-11497-6
>
>The book contains the answers to the questions in The C++ Programming Language
>(first edition).  Answers are limited to the language as described in the
>first edition of CPL.  To quote from chapter 1 "All solutions have been tested
>using compilers based on the AT&T cfront Translator, releases 1.2 and 2.0."

[Thanks to Bjarne and everyone for clarifying my original question.]

Does anyone know if Mr. Hansen plans on an updated version to correspond with
the Second Edition of TC++PL, as Tondo & Gimpel did with their "The C Answer
Book"?

Given that I've an original printing of the First Edition of TC++PL (with my
hand-pencilled in addendums & errata from Bjarne's original Usenet posting of
same! - ah, nostalgia (-: ), it's about time I got the new one, but I like
the warm fuzzies of an Answer Book - becoming mid-thirtysomething seems to
have reduced my brain cells sufficiently that I can't get all the questions
right by myself anymore (-:

--
	- Greg Earle				| Disclaimer: These are my
	  Itinerant Sun Consultant		| opinions only, not JPL's!
	  isolar!earle@elroy.JPL.NASA.GOV	| They just let me post through
	  (818) 353-8695			| their machines ...
Newsgroups: comp.lang.c++
From: dschieb@muse.cv.nrao.edu (Darrell Schiebel)
Subject: type conflict introduced by friend ...
Organization: National Radio Astronomy Observatory
Distribution: comp
Date: Tue, 29 Dec 1992 22:04:42 GMT


Since my last problem was handled so expediently, I have one other problem.
It seems that the "friend" declaration in the templated class "typeinfo_" 
below is causing the compiler to think that there are two "different"
"typeId" functions:

	class typeinfo {
	public:
	  virtual const char *name() const = 0;
	};

	template<class t> class typeinfo_ : public typeinfo {
	friend const typeinfo *typeId(t *);
	protected:
	  char *typename;
	  typeinfo_(char *name) : typename(name) {}
	public:
	  const char *name() const {return typename;}
	};

	template<class t> class templateClass {};
	template <class t> const typeinfo *typeId(templateClass<t> *) {
	  static typeinfo_<templateClass<t> > xx("templateClass");
	  return(&xx);
	};

	main() {
	  templateClass<int> *fred;
	  cout << (*typeId(fred)).name() << endl;
	}

So when the call to "typeId" is attempted in main, I get the error:

"test5.C", line 27: error: use of template function typeId() matches multiple instances

Any suggestions, on how to work around this. The constructor is "protected"
to force all access to the "typeinfo" structures to happen through the
"typeId" functions.

						Thanks,
						Darrell Schiebel
From: bucjet@uxa.ecn.bgu.edu (Jeffrey Terrell)
Newsgroups: comp.lang.c++
Subject: Converting EXE c++ files back to source code
Date: 30 Dec 92 01:08:58 GMT
Organization: Educational Computing Network

I have some old C++ programs that I written 2 or 3 yrs ago.  I have more
EXE files than C++ source code.  Some of these programs I've written are
quite good but I only have the EXE file that the compiler created.  I
was wondering if there is a way to convert the EXE files back to there
original source code?  Can it be done?

thanks
From: roy@mchip00.med.nyu.edu (Roy Smith)
Newsgroups: comp.lang.c++
Subject: Re: IS C++ a language for the "average programmer"
Date: 24 Dec 92 13:02:11 GMT
Organization: New York University, School of Medicine
NNTP-Posting-Host: mchip00.med.nyu.edu

ort@netcom.com (David Oertel) writes:
-> Newton used to solve problems using calculus and then publish his
-> solutions using algebra.  He didn't reveal calculus until the end of his
-> life when he was under competitive pressure from Leibniz.  I don't think
-> that anyone know for sure why he delayed, but he was extremely eccentric.

	He probably had an NSF grant deadline comming up and wanted to get
all those papers he'd been meaning to write all his life in press.
-- 
Roy Smith <roy@nyu.edu>
Hippocrates Project, Department of Microbiology, Coles 202
NYU School of Medicine, 550 First Avenue, New York, NY 10016
"This never happened to Bart Simpson."
From: plim@hpsgwr.sgp.hp.com (Peter Lim)
Date: Wed, 23 Dec 1992 00:39:50 GMT
Subject: Wanted C++, LEX++, YACC++ etc.
Organization: HP Singapore Asian Design Ctr
Newsgroups: comp.lang.c++

Hi Netlanders,

Can any kind soul please tell me where can I get the following? Preferrably
they should have been proven to work on HP-UX systems (both HP9000 series 300
and series 700?)

	[01]	A complete C++ compiler system
	[02]	Good class libraries for the above (X11 Widget, database?)
	[03]	Implementation of LEX and YACC useable with C++
		(LEX++ & YACC++ ???).

Information on where to get them (source code is almost a must here) and 
whether they work on both 300/700 or one or the other are welcome.
Hopefully, the above can be had for free. ie. public domain (or GNU
copyleft). If not, any info on pricing and availability would be much 
appreciated.

As the above might not be of interest to the general public, please e-mail
me if you have any info. Thanks.


Regards,     ___o``\____________________________________________ ___ __ _ _
Peter Lim.   V````\  @ @ . .. ... .- -> 76 MIPS at under US$20K !! - -- - -
                  /.-------------------------------------------- === == = =
             >--_//      . .. ... .- -> 57 MIPS at under US$12K !!
                `'
E-mail:  plim@hpsgwk.sgp.hp.com   Snail-mail:  Hewlett Packard Singapore,
Tel:     (065)-279-2289                        (ADC, ICBD-Singapore)
Telnet:        520-2289                        1150 Depot Road,
                                               Singapore   0410.

#include <standard_disclaimer.hpp>

Newsgroups: comp.lang.c++
From: twriter@rd.hydro.on.ca (Timothy Writer)
Subject: Re: profiling g++ code
Reply-To: twriter@rd.hydro.on.ca
Organization: "Ontario Hydro - Research Division"
Distribution: usa
Date: Mon, 21 Dec 92 22:35:48 GMT

ykim@cs.columbia.edu (Yong Su Kim) writes:


>I have a C++ program and I would like to profile it to see which
>functions are taking the most time so that I can optimise those
>functions. 

>I tried g++ -p, but I get an error message saying that the symbol
>"mcount" is undefined.

On many systems you need to link with a profiling library, for example
/usr/lib/libc_p.a (Sun) or /usr/lib/libprof1.a (SGI).  The -p option of
g++ (gcc) is supposed to take care of this for you; however, on some
systems it may not, for example, my SGI.  On my system g++ -p -v
illustrates the problem:

	...
	/very-long-path/ld /usr/lib/mcrt1.o ... file.o -lg++ -lgcc -lc_p ...

Do you see the problem?  g++ is trying to link libc_p not libprof1.  Of
course, the proper fix is to patch g++ which is not difficult but I
haven't had time.  The short term solution is to add -lprof1 to the g++
command line and create a dummy libc_p.a in the current working
directory:

	ln -s /usr/lib/libc.a libc_p.a
	g++ -L. -p -v file.o -lprof1

As you didn't tell us what kind of system you are using, I can't say if
this fix will work for you but you should be able to do something
similar.

>Are there other ways, or other programs which will allow me to
>determine which functions are taking the most time?

Tim

-- 
Tim Writer			     phone:  (416) 231-4111 ext. 6990
Ontario Hydro Research Division	     fax:    (416) 237-9285
Toronto, Ontario		     e-mail: twriter@rd.hydro.on.ca
CANADA
Newsgroups: comp.lang.c++
From: cshaver@informix.com (Craig Shaver)
Newsgroups: comp.lang.c++
Subject: Re: feedback wanted on appropriate OOPL
Date: 29 Dec 92 01:13:54 GMT
Organization: Informix Software, Inc.

In article <1992Dec28.173620.14793@microsoft.com> jimad@microsoft.com (Jim Adcock) writes:
>In article <92358.192930COP80196@UCF1VM.BITNET> Bill Laird <COP80196@UCF1VM.BITNET> writes:
..... deleted .....
>
>Three points from my perspective:
>
>1) I have known many OO programmers coming from a Smalltalk background
>into C++.  I found them very difficult to work with, because they aways
>tend towards trying to use a Smalltalk approach to C++, and C++ is not
>Smalltalk, nor vice versa.  Good programming technique is not the same
>between the two languages.
>
>2) Having just done an interview with a interview candidate who has
>an MS in CS, who claimed C/C++ as a primary language, but who couldn't 
>program simple problems in a straight-forward manner, using style
>appropriate for the C/C++ languages, I must again express frustration
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I have used both Smalltalk and C++ and do not agree with your conclusions
without concrete evidence to the contrary.  Could you please elaborate
on what style is appropriate for c/c++?  It would be a help to have
some references to material that clarifies the differences in OO style.

>at CS departments who don't teach students the skills they need to
>get a job.  C is the mainstream programming language for the software
>industry.  C++ is the mainstream OO programming language for the
>software industry.  Non-mainstream languages are fine for PhD candidates
>who plan to remain in acedemia.

I thought COBOL was the mainstream language?  Could you support this 
set of statements with some examples? Evidence? 

>
>3) Neither 1) nor 2) above is as important as having students who 
>know and can perform the necessary applied mathematics.

This is a very broad statement.  Could you give an example please?

-- 
Craig Shaver  (cshaver@informix.com for now) (415)390-0654 (415)926-6407
Productivity Group POB 60458 Sunnyvale, CA  94088
Newsgroups: comp.lang.c++