[net.lang] C++

bs@alice.UUCP (Bjarne Stroustrup) (01/15/85)

Here is a few examples of how C++ can be used to handle some of the
ideas/problems mentioned recently on netnews:

Comments:
	C++ has both standard /* */ comments, and // comments to the end of line,
	each can be used to comment out the other.

Union initialization:
	There is no separate feature for initializing unions in C++. However, the
	general mechanism for initializing a class object can be used. The two
	functions called "u" do the job; the correct one is chosen based on the
	type of the initializer; such functions are called constructors;
	a constructor has the same name as its class/struct/union:

	union u {
		int a;
		char* p;

		u(int aa) { a = aa; }
		u(char* pp) { p = pp; }
	};

	f() {
		u x = 1;	// assignment to x.a
		u y = "asdf";	// assignment to x.p
	}

	The u() functions will be inline substituted, so the code generated in f()
	reduces to two move instructions: x<-1 and y<-"asdf";
	Clearly there could be a more compact notation for specifying this
	particular initialization, but the full power of a function comes in
	handy for non-trivial examples.

Input and output:
	Like C, C++ hasn't got any.
	If you like the printf/scanf family of functions you can use it,
	or you migth try the stream library. The stream library provides
	flexible, extendable, and type-secure i/o; output is  unformatted.
	The most common operations are provided in the form of the operator
	<< for output and >> for input. For example, using the standard output
	stream cout:
		int i; float d; char* p;
		...
		cout << "i = " << i << " d = " << d << " p = " << p << "\n";
	note that each item is written out according to its type.
	Sometimes this style looks better than printf, sometimes it looks worse,
	but there can be no type errors and it is easy to define << to take
	operands of user-defined types.

Common part of two structures:
	First declare the structure that should be common:

	enum fruit_type { _apple, _pear };
	
	struct fruit {
		fruit_type type;
		// more fruit data
	};

	Then use "fruit" as the "base" for "derived" classes:

	struct apple : public fruit {
		// apple data
	};

	struct pear : public fruit {
		// pear data
	};

	f(fruit* p) {
		switch (p->type) {
		case _apple:
			...
		case _pear:
			...
		default:
			cerr << "error, bad fruit\n";
		}
	} 

External names:
	C++ cannot be used in any reasonable way on a system that does not
	support long external names.

Some or even most of this may look strange at first glance,
but it all fits together, and it all fits with C.
More information can be found in the UNIX issue of the BLTJ,
and yet more from the AT&T Bell Labs Technical Reports on C++.

C++ has been released to educational users ONLY;
a prototype C++ compiler is distributed by

	AT&T Technologies, Inc.
	Software Sales and Marketing
	P. O. Box 25000
	Greensboro, NC 27420 

(or phone 1-800-828-UNIX).

- Bjarne Stroustrup, AT&T Bell Labs, Murray Hill, NJ

bs@alice.UucP (Bjarne Stroustrup) (11/19/85)

> From allegra!ulysses!gamma!epsilon!mb2c!umich!cosivax!mts Wed Dec 31 19:00:00 1969
> From: mts@cosivax.UUCP (Michael Stolarchuk)
> Subject: data type preprocessors
> Organization: COSI, Ann Arbor, MI

> I am interested in data type preprocessors for C.  The two
> I would like information on are objective C, and C++.

> Any information is useful, including information about how to
> get the products, experience with the products, and any
> problems.

> Thanks.

C++ is available educationally & commercially in source form
In the US try, AT&T Software Sales and Marketing, PO Box 25000,
Greensboro, North Carolina 27420, (800) 828-UNIX or (919) 279-3666.
In Europe, try contacting UNIX Europe.

They have documentation. You can also try the C++ book:
	Bjarne Stroustrup: The C++ Programming Language.
	Addison Wesley, ISBN 0-201-12078-X. Just published.

C++ is C with a few problems fixed:
	- function argument type checking and type conversion
	- scoped & typed constants (alternative to #define)
	- inline functions (alternative to #define)
	- etc.
C++ provides a facility for user-defined types:
	- Simula-like single-inheritance class concept
	- data hiding
	- operator overloading
	- (optional) guaranteed user-defined initialization and cleanup
	- user-defined type conversion
	- dynamic typing (virtual functions).


All the usual claims about data abstraction, object based programming,
code re-usability, programmer productivity, maintainability, efficiency,
etc. has been made for C++. Some are undoubtedly true. See for yourself.
	
C++ has been in use for about 3 years now.

It runs on most UNIX boxes (AT&T 3Bs, VAXs, M68Ks, Ahmdals, Pyramids, etc.).
You typically need access to a 3B or a VAX to get started.

C++ is a complete language, not just a set of constructs to be expanded by a
preprocessor. The released compiler fron-end produces C as an intermediate form
instead of generating assembly code or binary. All error messages comes from
the C++ front end and you can use a symbolic debugger on C++ programs.

	- Bjarne Stroustrup (AT&T Bell Labs, Murray Hill)

axel@tub.UUCP (01/04/86)

Subject:  C++: statics in classes == classvariables ?

	I am currently writing a paper about the concept of
inheritance used in object oriented programming languages.
I have a question about the C++ mechanism for static members of a class. 

Chapter 8.5.1 of the C++ Reference Manual states:
"...There is only one copy of a static member shared by all
 objects of the class in the program. ..."

	What about derived classes and a static member of a base class.
Is only one copy of this static member shared by all objects of the 
base class and its derived classes?  (This would be like the concept
 of class variables in Smalltalk or Loops)

I would appreciate comments and answers !

Thanx a lot			Axel

e-mail: ...!mcvax!unido!tub!axel.UUCP
mail: Axel Kramer, Schiller Str. 27, 1000 Berlin 12, W.Germany