HDTenEightyP/NetNews huggingface dataset:
From: rmartin@thor.Rational.COM (Bob Martin)
Subject: Re: Multiple Header Files Problem
Organization: Rational
Date: Wed, 11 Nov 1992 00:41:34 GMT

reindorf@us-es.sel.de (Charles Reindorf) writes:

|In article <rmartin.721359424@thor>, rmartin@thor.Rational.COM (Bob Martin) writes:
||> A more interesting variation on this issue is the problem of "circular
||> 
||> [ etc.]

|It is usual, in header files, to structure them so :


|| # ifndef <HeaderFileName>_h
|| # define <HeaderFileName>_h
|| 
|| 
|| ... body of include file ...
|| 
|| 
|| # endif

|This prevents cyclic dependencies and has been in common practice for, well, ages.

Of course!  And of course I use this technique myself, and instruct my
students to do the same. 

What I had not realized, until you (and many others) pointed it out to
me, is that the #ifndef convention breaks inclusion cycles.  Of course
it does.

I have run into inclusion cycles several times in the past few years.
The first one I ran into, was of my own creation.  This was before I
knew about the #ifndef convention.  I discovered that convention at a
separate time, and used it to solve a different problem.  So the two
never gelled together in my brain.  The other cycles I have stumbled
accross were written by clients of mine who were just starting at C++,
and had not yet learned all the conventions.

However, using the #ifndef convention does not solve all the problems
related to inclusion, nor obviate the need to make judicious use of
forward declarations.  #ifndef, while it *does* keep the contents of a
header file from being compiled more than once, does not keep the
header file from being *read* more than once.  Thus, if care is not
taken, compile times can grow quite long.

Moreover, some compilers limit the number of files that they will
include, or at least the depth of the inclusions.  

So, take care when using #include in a header file.  Always be sure
that you the #include is necessary, and that it cannot be replaced
with a forward declaration.



--
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++
From: matt@centerline.com (Matt Landau)
Newsgroups: comp.lang.c++
Subject: Re: something nasty
Date: 13 Nov 1992 06:58:47 GMT
Organization: CenterLine Software, Inc.
NNTP-Posting-Host: 140.239.1.32

In <1992Nov13.050829.952@BofA.com> dan@BofA.com (Dan Brockman) writes:

>I have received much correspondence of late regarding
>error message "...bus error or something nasty...".  Many
>have seen it, and each seems to have traced it to a different
>specific problem.  No strong patterns.  Many suggested
>"get another compiler".  

That's because there *is* no one specific cause of the problem.  

The message you're seeing is cfront's all-purpose error message for 
situations when things go awry and the C++ translator either crashes 
or gives up due to internal errors of some sort.

In my own experience, I've tended to see internal errors when trying to 
compile expressions that are too complicated for cfront (which you can 
often deal with by finding the offending expression and simplifying it, 
splitting into multiple statements and introducing explicit temporaries 
as needed), and pushing too hard on nested classes in cfront 2.1.x
--
 Matt Landau			Waiting for a flash of enlightenment
 matt@centerline.com			  in all this blood and thunder
From: pkr@media03.UUCP (Peter Kriens)
Newsgroups: comp.lang.c++
Subject: stupid bug with NIHCL & sun ompiler
Date: 9 Nov 92 21:12:55 GMT
Organization: Mediasystemen, Netherlands
X-Newsreader: Tin 1.1 PL4


I am looking for people who could help me on the
following puzzling problem:

class A {
public:
	String s;
	[virtual] void t();
};

main()
{
	A a,b;
	a.s="abc";
	b.s="def";
	a = b;
}

without the virtual, no problem C++ uses the = operator for
s from the String class and a new pointer is created.

with the virtual operator, it uses a bit wise assignment
and a.s will now point to the same memory location
as b.s. Problems!

Anybody knows something about this?

	Peter Kriens
From: tmb@arolla.idiap.ch (Thomas M. Breuel)
Newsgroups: comp.lang.c++
Subject: Re: Discriminating Variant Records Without switch() ??
Date: 13 Nov 92 20:52:54
Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
	Perceptive)
	<BAB.92Nov12074430@se39.wg2.waii.com> <1992Nov12.190518.20213@bnr.ca>
Reply-To: tmb@idiap.ch
NNTP-Posting-Host: arolla.idiap.ch
In-reply-to: holiday@bnr.ca's message of Thu, 12 Nov 1992 19:05:18 GMT

In article <1992Nov12.190518.20213@bnr.ca> holiday@bnr.ca (Matthew Holiday) writes:

   One thing that would help would be the ability to "transmute" an
   object into a subclass of the object's current class.  That is, the
   factory could create a top-level object.  After some processing,
   this object could determine that it's really more specialized, and
   turn itself into a subclass object.  Take a trivial example: a
   shape is constructed using some points.  Further processing reveals
   that the points define a rectangle, so the shape converts itself
   into a rectangle.  Yet more processing reveals that the rectangle
   is in fact a square -- so it becomes an object of type square,
   which was derived from rectangle and shape.  One of the problems
   with this downward transmutation is that if you simply replace the
   object, it will have a new address, so you have to update all
   pointers to the object every time it is replaced.  You can't
   necessarily transmute in place, because the new subclass object may
   be too large to fit into its current space in memory.  In addition
   to this "transmute" capability, downcasting is also useful (see
   Stroutrup's RTTI papers).

You can "transmute in place" if you put an object in between:

struct GeneralShape;
struct Point:GeneralShape;
struct Rectangle:GeneralShape;

enum {SHAPE_NONE,SHAPE_POINT,SHAPE_RECTANGLE} ShapeTag;

class TransmutableShape {
private:
	int which_shape;
	GeneralShape *the_shape;
public:
	void operator=(Point *obj) {
		the_shape = obj;
		which_shape = SHAPE_POINT;
	}
	void operator=(Rectangle *obj) {
		the_shape = obj;
		which_shape = SHAPE_RECTANGLE;
	}
	// ...
	operator Point *() {
		if(which_shape!=SHAPE_POINT) return 0;
		else return (Point *)the_shape;
	}
	operator Rectangle *() {
		if(which_shape!=SHAPE_RECTANGLE) return 0;
		else return (Rectangle *)the_shape;
	}
	// ...
};

This is essentially what the implementation would have to
do anyway.

				Thomas.
Newsgroups: comp.lang.c++
From: mcrocker@titan.ucc.umass.edu (MATTHEW S CROCKER)
Subject: C++ sockets using iostream
Organization: University of Massachusetts, Amherst
Date: Thu, 12 Nov 1992 16:08:09 GMT


 Is there currently a socket class derived from iostream so that
I canr treat an socket like a stream??
 
example

 socketstream& mysock;

 mysock.open(titan.ucc.umass.edu,1234);
 mysock << "this is a line of text to the socket" << endl;
 mysock >> buf;
 
 cout << buf << endl;


I would like to be able to further this class by adding object
handling through the socket.

class message
{  
 private:
  long messageID;
 public
 socketstream& operator<<(socketstream& st, message&);
}

where the message class would send the messageID down (or object ID)
which is unique.. on the other end of the socket the recieving client
would see the messageID and know which object to assign the following
data to that object would be responible for reading the data off of
the stream in the same way it was written  (much like borlands
resource's) I don't think that this would be too hard to do.. However
I would just as soon not try to build something if there is currently
a working version.

Thanks,

-Matthew S. Crocker
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Matthew Crocker
s1949782@titan.ucc.umass.edu <-  Til 1/1/93
mcrocker@titan.ucc.umass.edu <-  Til I Graduate  LOOOOOOOONNG TIME
From: nikki@trmphrst.demon.co.uk (Nikki Locke)
Newsgroups: comp.lang.c++
Subject: Re: Debugging output
Date: 11 Nov 92 12:01:30 GMT
Reply-To: nikki@trmphrst.demon.co.uk
Organization: Trumphurst Ltd.
X-Mailer: cppnews $Revision: 1.20 $

In article <DAVIDM.92Nov7163528@consilium.com> davidm@consilium.com (David S. Masterson) writes:
> void
> Tracer::SetWatch(char* name)
> {
>         if (watch)
>                 delete watch;
> 
>         watch = new char[strlen(name)];
                           ^^^^^^^^^^^^ Oops !
Ever get unexplained core dumps using this ?
>         strcpy(watch, name);
> }
-- 
Nikki Locke,Trumphurst Ltd.(PC and Unix consultancy) nikki@trmphrst.demon.co.uk
trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
Newsgroups: comp.lang.c++
From: f43703a@nucc.cc.nagoya-u.ac.jp (SUPRATIC GUPTA)
Subject: Read from file/write to screen or other file?? please help.
Organization: Nagoya University Computation Center, Nagoya, Japan.
Date: Thu, 12 Nov 1992 05:50:35 GMT


 want to read a text file in and print it in the sreen. Can any one
help me in reading and printing. I will be most thankful if you can
answer me personally.

with regards
SUPRATIC GUPTA
From: brendan@cygnus.com (Brendan Kehoe)
Newsgroups: comp.lang.c++
Subject: Re: Invoking template base ctor
Date: 9 Nov 92 21:43:34 GMT
Reply-To: brendan@cygnus.com
Organization: Cygnus Support, Palo Alto CA; Phone +1 415 322 3811
In-reply-to: vander@flab.fujitsu.co.jp's message of 6 Nov 92 02:56:33 GMT

In article <VANDER.92Nov6115633@vancouver.stars.flab.Fujitsu.co.jp> vander@flab.fujitsu.co.jp (Mike van der Velden) writes:

   I'm using g++ (2.2.2?) on a Sun Sparc S-4/1X.  I have the following
   code segment.

       template <class T>
       class B {
       public:
	   B () { /*  */ }
       };


       class D : public B<D> {
       public:
	   D() : () {}     // compiles fine
	   D() : B() {}    // error:  class `D' does not have any field named `B'
       };


Please try the 2.3.1 release, it says:

  foo.C:11: `D::D ()' is already defined in class D
  foo.C: In method `D::D ()':
  foo.C:10: warning: ANSI C++ forbids old style base class initialization

--
Brendan Kehoe                                               brendan@cygnus.com
Cygnus Support, Palo Alto, CA                                  +1 415 322 3811

Newsgroups: comp.lang.c++
From: joe@proto.com (Joe Huffman)
Subject: Re: 32 bit compiler
Organization: FlashTek, Inc.
Date: Wed, 11 Nov 1992 08:23:28 GMT

erc@netcom.com (Eric Smith) writes:

>The only real complaint I have is that Zortech and Microsoft are so
>incompatible with each other, I have to keep rebooting my computer to
>switch back and forth while porting.  Programs compiled with Zortech's
>32-bit X model apparently won't work with NT, even though they are
>supposed to be Windows compatible.  

FlashTek supplies the X model DOS extender for Zortech/Symantec... and
I work for FlashTek.

The problem is that Windows NT does not (at last report anyway) provide
a DPMI host.  The extender works just fine with Windows 3.0 and 3.1
and other DPMI hosts.  When/if MS provides a DPMI host under NT then
you will find applications built with the extender will work.

-- 
netcom!proto!joe
joe@proto.com
Newsgroups: comp.lang.c++
From: arthur@solomon.technet.sg (Arthur Sombrito)
Subject: forward class declarations
Organization: National University of Singapore
X-Newsreader: TIN [version 1.1 PL6]
Date: Thu, 5 Nov 1992 09:18:43 GMT





Hi,

I'd like to ask the ARM specifications regarding forward class
declarations.  At what scope would the class name be entered?  
The current scope or the first non-class enclosing scope?  
For example:

  class A {
    class B {
      struct C;              // is it ::C or A::B::C ?
      struct D *dP;          // likewise is it ::D or A::B::D ?
      void f(struct E *eP);  // is it ::E or is it entered in
                             // the local scope of f() ?
    };
  };
  C *cP;                     // so is C visible?
  E *eP;                     // and so is E?

The USL library assumes that forward class declarations are 
entered in the first non-class enclosing scope. As far as I 
could tell in ARM, it should be entered in the current scope.
Which should it be?

Thanks for any replies
Newsgroups: comp.lang.c++
From: acoles@bcars6a1.bnr.ca (Andrew Coles)
Subject: Mark V Systems (ObjectMaker)?
Reply-To: ACOLES@BNR.CA
Organization: BNR Carling, Ottawa
Date: Tue, 10 Nov 1992 19:51:12 GMT

Does any know the phone number or address Mark V Systems Ltd?
They make a product called ObjectMaker.

Thanks in advance
Organization: The American University - University Computing Center
Date: Fri, 6 Nov 1992 18:44:52 EST
From: Kayvon Z. Sadeghi <KSADEGH@auvm.american.edu>
Newsgroups: comp.lang.c++
Subject: const char *

Hi

I was wondering if there is any difference between the way C, and C++
handle the "const char *" decleration. You see, I have this peice of code
that I know it works on C, but my C++ compiler behaves a bit strange.

I have this subroutine call that says:

mycall("");


and then somewhere down in my code I have:

 mycall(const char *msg){
     if(msg=="")
          dothis();
     if(msg!="")
          dothat();
}

Strange, but my compiler doesthat() instead of dothis().
I even checked the value of msg and it *IS* equal to "". Is something wrong
with my C++ compiler or what? or are strings treated differently in here?

thanks
k1
---
------------------------------------------------------------------------
     Of Course,  I Could Be Wrong !!!
------------------------------------------------------------------------
Kayvon Sadeghi                    k.sadeghi@ieee.org
Voice:202/244-0789
Newsgroups: comp.lang.c++
From: nh@cbnewsg.cb.att.com (nicholas.hounsome)
Subject: Re: Bad 'for' statement?
Organization: AT&T
Date: Fri, 13 Nov 1992 08:59:13 GMT

From article <1992Nov12.160420.18097@rs6000.bham.ac.uk>, by pickerig@eee.bham.ac.uk (Mr. G. Pickering):
> Hi,
> 
> Could you tell me if this is really a syntax error as AT&T 2.1 reports?

Yes it is.

> 
>   for(int i=0, int j=10;   i<10;   i++, j++)
>   {
>     // do something
>   }

The first part must be either an expression or a declaration statement.

The usual C

for(i=0,j=10 ...

is an expression in which ',' is an operator NOT a separator - this tends to be
overlooked because ',' is rarely used as an operator.
If you wrote:

int i=0, int j = 10;

You would not expect it to compile and so it wont in the "for".
Of course in this case it is possible to write:

for(int i=0,j=10;...

Since the first part is a valid declaration statement. One  can even have ints
, arrays of ints, functions returning int or any combination of these but not
an int and a short say. It is only included as a convenience for a 
common programming construct and IMHO it was a mistake. (It would have
been better if the scope was limmited to the for loop - what I find is 
that I want several fors and I cannot use the same variable in each.

> 
> Thanks,
> 
> Guy
> 
> --
> +--------------------------------+-----------------------------------------+
> | Guy Pickering                  | School of Electronic & Electrical Eng,  |
> | E-MAIL: G.PICKERING@uk.ac.bham | University of Birmingham,               |
> | Tel: (021) 414 4340            | Edgbaston, Birmingham. B15 2TT.         |
> +--------------------------------+-----------------------------------------+
> | "I have ten pairs of trainers...One for each day of the week" - Sam Fox  |
> +--------------------------------+-----------------------------------------+

Nick Hounsome
AT&T Network Systems UK Ltd.
From: rose@t524i5.telematik.informatik.uni-karlsruhe.de (Ortwin Rose)
Newsgroups: comp.lang.c++
Subject: Re: Problem with DEC C++ ?
Date: 5 Nov 92 12:17:23 GMT
Organization: /usr/users/rose/.organization
NNTP-Posting-Host: t524i5.telematik.informatik.uni-karlsruhe.de
In-reply-to: Gilles_Kohl@spam.fido.de's message of Mon,  2 Nov 92 17:57:00 +0100


Hi,

let me start with a short answer:
The error-message given below is wrong, but it doesn't occur with the
newest release of DEC C++ (rel. 1.2). Now to the details:

> During a port of (a subset of) the NIHCL to DEC C++ (from Glocken-
> spiel) we encountered the following problem. In the source given below,
> DEC C++ issues an error while other compilers (we tried AT&T cfront 2.1,
> Glockenspiel, BC++ 3.1) do not complain.
> 
> // --- Cut here ---
> 
> #include <iostream.h>
> 
> class Base {
> public:
>    virtual int f()       { return 1; }
>    virtual int f() const { return 2; }
> };
> 
> class Derived : public Base {
> public:
>    void test();
> };
> 
> void Derived::test()
> {
>    cout << f() << endl;
> }
> 
> main ()
> {
>    Derived k;
> 
>    k.test();
> }
> 
> // --- cut again ---
> 
> cpptest.C:16: error: In this statement, the argument list "" matches more than 
> one "Base::f".

Well, a tricky situation. However, according to the ARM, p. 320:

  "..."constness" acts as a tie-breaker where needed but does not affect
   argument matching otherwise. This is especially important for ... const
   member functions".

Since Derived::test() is called as "k.test()", this means (ARM, p. 317):

  "Where a member of a class X is explicitly called for a pointer using the
   '->' operator, this extra argument is assumed to have a type 'const X*' for
   'const' members ... and X* for others. Where the member function is explicitly 
   called for an object using the '.' operator ... this extra argument is
   assumed to have type 'const X&' for const members ... and X& for others."

Now, since test() is NOT declared to be a 'const' member function, it will
see the 'X&' type for its extra argument, and should thus call the non-const
function f() of its base-class. Making Derived::test() a const member
function will cause it to call the other instance of f().

With regard to your question about using DEC C++:
I am working with DEC C++ for more than 1 year, and I think it is one of
the best C++ compilers available. It is very restrictive, giving you hints
about almost any violations of the ARM. 
By the way, the same code compiles and runs correctly with my release of cxx,
which identifies itself (using the -V switch) as

   DEC C++ for ULTRIX on RISC V1.2

Thus, if you WRITE code that passed cxx, you can almost be sure that it will 
compile with any other compiler (I am also working with AT&T CC, GNU C++, 
Borland C++ and Zortech C++). However, if you have to PORT something, using 
cxx can be quite time-consuming since you often have to correct many mistakes
the original writers made.


Regards

-- O. Rose
   University of Karlsruhe
   Institute of Telematics
   Germany

   rose@telematik.informatik.uni-karlsruhe.de
From: pluto@cs.ucsd.edu (Mark Plutowksi)
Newsgroups: comp.lang.c++
Subject: Re: operator [][]
Date: 9 Nov 92 19:03:38 GMT

pandrews@lovat.fmrco.com (Paul Andrews) writes:


>> for multiple dimension array, is it possible to define 
>> an operator [][](say for two dimensions)? I try to define 
>> it as 
>> int & operator[][] (int, int);
>> 
>You can only overload single []. Remember though that this generates a function call
>like:
>	<class>.operator[](<arg>)

>which returns a value. So make that value be a reference to another class which also
>has an operator[] overload. Then when you specify:

>	<classA>[<arg1>][<arg2>]

>you will actually get

>	<classA>.operator[](<arg1>).<classB>.operator[](<arg2>)

>classB should now call a well-known function in classA to indicate what argument was
>passed to it. A good way of doing this is for classA to inherit yet another class
>(classC!) which has a well-known virtual function which classA overrides. That way
>both classC and classB can be re-used whenever you want to have multiple [].

>Simple huh?

>(apologies if the syntax of the expanded function calls isn't quite correct).

>(I would be interested to know if anyone has any other ways of doing this).

>(Is there any standard nomenclature for classes like C and B above? something like
>classB is a slave class, classC is a functor or what?)

>---
>---
>Paul Andrews


I think that what I did is another way:
I have a Matrix class that contains a data member which is 
an array of pointers to Vectors, where Vector is another class, whose
primary data member is an array of pointers to some number type (double, int, ...)  
Let aVec be a vector.  Then, aVec[i] gives its i-th element, (because I specified
the [] operator as above.)  So, I just give the Matrix class the [] 
operator as well, and voila, aMatrix[][] gives me what I want -
which I gather is also what you're trying to do.
It does, however, distribute the internal storage of your array
(whereas as I understand it the above solution retains the array
as a single object referenced by two classes using two access functions)
In my case, this was desirable, because splitting up large arrays
into small Vectors grouped into a Matrix allowed me to use arrays much
larger than the 64K segments my machine constrains me to. 

.
.
.
.
.
.
.
.
i

have

no

signature


please 


let 


this


suffice

Mr.

Auto

reject

Program

Sir
From: bab@se39.wg2.waii.com (Brian Button)
Newsgroups: comp.lang.c++
Subject: Discriminating Variant Records Without switch() ??
Date: 10 Nov 92 12:33:24 GMT
Organization: Western Geophysical Exploration Products

Is there a simple, OOP based way to discriminate between variant
records? I saw an article in C Users Journal last month titled "Switch
Deemed Harmful to C++" or something like that, but I couldn't figure
out how to do it any other way.

As an example:

We're reading structures sent to us over a socket. Since these
structures are being sent and received on the same machine, we can
just memcpy the byte stream read from the socket into a big union, and
then switch based on the first field of the union to determine the type.

As a trivial example:

{
	read( sd, buf, 16 );
	memcpy(( char * )&union_of_structs, buf, 16 );
	switch( union_of_structs.type )
	{
		case A:

			.
			.
			.
	}
}

This works, but doesn't look very OOP-ish. Can anyone give me any
suggestions about how this can be reformed to fit in with the object
paradigm and not use the switch statement?

Thanks in advance,

bab

	
--
|-----------------------|----------------------------------------------------|
| Brian Button          | email : button@wg2.waii.com                        |
| Design Engineer       |         71023.276@compuserve.com                   |
| Western Geophysical   | voice : (713)964-6221                              |
| 3600 Briarpark        |----------------------------------------------------|
| Houston, Texas  77042 |                  Opinions Be Mine!!                |
|-----------------------|----------------------------------------------------|
Newsgroups: comp.lang.c++
From: haechler@bernina.ethz.ch (Stefan Haechler)
Newsgroups: comp.lang.c++
Subject: member test?
Date: 6 Nov 92 08:16:58 GMT
Article-I.D.: bernina.1992Nov6.081658.29693
Organization: Swiss Federal Institute of Technology (ETH), Zurich, CH
X-Newsreader: Tin 1.1 PL5

How can I know which dynamic type has a variable ?

e.g.

class A { .... } ;
class B: public A { ... } ;

// variable declaration 

A *a ;


// initialization

a = new B;

// now the dynamic type of "a" is B

// my question:
// is there a statement for testing if a is member of B
// e.g 
  if (member(a,B) == true) ..... else ..... ;


thanks and  best regards

wolfgang
Newsgroups: comp.lang.c++
From: frank@Cookie.secapl.com (Frank Adams)
Subject: Re: Making qsort type-safe
Date: Wed, 11 Nov 1992 16:38:55 GMT
Organization: Security APL, Inc.

In article <1992Nov09.155723.112061@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
>In article <dak.721261218@messua> dak@messua.informatik.rwth-aachen.de (David Kastrup) writes:
>>walduck@mpr.ca (Andrew Walduck) writes:

My apologies; the line above should have been deleted.  The quoted lines are
from David Kastrup.

>>Quicksort needs some tuning to get really good.  [...]
Newsgroups: comp.lang.c++