HDTenEightyP/NetNews huggingface dataset:
From: spencer@cats.ucsc.edu (Michael Spencer)
Newsgroups: comp.lang.c++
Subject: Re: Function 'max' should have a prototype
Date: 25 Jan 1993 23:36:38 GMT
Organization: University of California, Santa Cruz
NNTP-Posting-Host: am.ucsc.edu


hrpctw@pnv.palm.cri.nz (Colin T. Wilson-Salt) writes:

>I can't seem to get the max() macro to work.  It works OK under C, but
>under C++ it gives me the error "Function 'max' should have a prototype".

>Should I give up and write a replacement max() function/macro?

Roll your own. It's a lot easier than trying to figure out the
vagaries of compilers!  Try:

#define Minim(a,b)            ((a<b) ? a : b)
#define Maxim(a,b)            ((a>b) ? a : b)
#define InRange(a,lo,hi)      ((a<lo) ? 0 : ((a>hi) ? 0 : 1))
#define RangeSet(a,lo,hi)     ((a<lo) ? (a = lo) : (a>hi) ? (a = hi) : a )
#define CircleSet(a,lo,hi)    ((a<lo) ? (a = hi) : (a>hi) ? (a = lo) : a )

The last 3 will help avoid 'fence-post' errors.


===========================================================================
Michael Spencer            |      2640 Borregas
spencer@cats.ucsc.edu      |      Aptos, CA   95003
===========================================================================

-- 

===========================================================================
Michael Spencer            |      2640 Borregas
spencer@cats.ucsc.edu      |      Aptos, CA   95003
===========================================================================
From: dulimart@cps.msu.edu (Hansye S. Dulimarta)
Newsgroups: comp.lang.c++
Subject: Linked list of several classes.
Date: 21 Jan 1993 04:58:55 GMT
Organization: Department of Computer Science, Michigan State University
Distribution: world
NNTP-Posting-Host: pixel.cps.msu.edu
Originator: dulimart@pixel.cps.msu.edu


To C++ gurus:
  I am having problem with defining a "generic" linked list. For instance,
I would like to define a linked list of furnitures where each element can
be either a Desk or a Table. The immediate "solution" that came to me was
to define four classes:

	1) List (for the list)
	2) ListEl (for the list item)
	3) Desk (derived from ListEl)
	4) Table (derived from ListEl)

Also, inside class List, I definde a method "search" that will return the
pointer to a ListEl and another method "append" that will append a new
element to the list. 

Function "append" behaves as I expected, that is, I can add element of
class Desk and Table to the list like in the following:

    List inventory;

    inventory.append (new Desk(/*...*/));
    inventory.append (new Table(/*...*/));

BUT......
  Whenever I do a 'search' I would like to get a return value of type
  'Desk *' or 'Table *' depending on the element in the list that satisfies
  the search criterium. But the code, as it is written, always returns a
  'ListEl *' and I lost the information whether the element is a Desk or a
  Table. I don't see a simple way to do this in my code.

I really appreciate if some C++ gurus are willing to answer my question.

My code, more or less, looks like the following:

class ListEl;

class List {
private:
  ListEl *head;
public:
  ListEl* search (/* some args here */);
  void append (ListEl *);
};

class ListEl {
  ListEl *next;
  friend class List;
};

class Desk : public ListEl {
  /* ... */
};

class Table : public ListEl {
  /* ... */
};


 |_|_|_|_|      Hans Dulimarta [dulimart@cps.msu.edu]        |_|_|_|_|
   |_|_|_| Pattern Recognition & Image Processing Laboratory |_|_|_|
     |_|_|         Department of Computer Science            |_|_|
       |_|            Michigan State University              |_|
-- 
|_|_|_|_|  _|_|_ |_|_|_|_| Hans Dulimarta [dulimart@cps.msu.edu]
|_|_|_|  _|_| |_|_ |_|_|_| Pattern Recognition & Image Processing Laboratory
|_|_|  _|_|_ X _|_|_ |_|_| Department of Computer Science
|_|   |_|_|_|_|_|_|_|  |_| Michigan State University
From: barmar@think.com (Barry Margolin)
Newsgroups: comp.lang.c++
Subject: Re: name of object
Date: 28 Jan 1993 20:58:22 GMT
Organization: Thinking Machines Corporation, Cambridge MA, USA
NNTP-Posting-Host: telecaster.think.com

In article <1993Jan28.173602.5232@gmuvax2.gmu.edu> twallace@gmuvax2.gmu.edu (Todd Wallace) writes:
>Here is an odd question for the OOP gurus:
>Is there a way for an object to know its own name?

There's no built-in way in the language.  Some objects don't even have
names.

>For instance, let's say we declare the following class:
>class Lemon {
>	public:
>	//some stuff
>};
>
>void main(void)
>{
>	Lemon A,B,C;
>
>	A.tell_me_your_name;
>	B.tell_me_your_name;
>	C.tell_me_your_name;
>}

How's this:

class NamedThing {
	char *name;
    public:
	void tell_me_your_name() {cout << name << '\n';};
	NamedThing(char *initial_name) {name = initial_name;};
};

class Lemon: virtual public NamedThing {
	...
};

void main(void) {
	Lemon A("A"), B("B"), C("C");
	A.tell_me_your_name;
	B.tell_me_your_name;
	C.tell_me_your_name;
}

If you don't like having to write the name twice, use a macro:

#define NAMED(name) name(#name)

Then you can write:

	Lemon NAMED(A), NAMED(B), NAMED(C);

	Lemon *foo_ptr = NAMED(foo);



>
>and I would like the output to be:
>A
>B
>C
>
>Therefore, I have to declare a member function for Lemon that
>can look up its own name.
>
>Can it be done? It would help a lot with debugging.
>
>
>----------------------------------------------------------------
>|    Todd Wallace               |  "A pessimist is surprised   |
>|    twallace@gmuvax2.gmu.edu   |   as often as an optimist,   |
>|                               |   but always pleasantly."    |
>|                               |            - Robert Heinlein |
>----------------------------------------------------------------
>


-- 
Barry Margolin
System Manager, Thinking Machines Corp.

barmar@think.com          {uunet,harvard}!think!barmar
Newsgroups: comp.lang.c++
From: kanze@us-es.sel.de (James Kanze)
Subject: Re: Function 'max' should have a prototype
Organization: SEL
Date: 28 Jan 93 19:49:56

In article <1k1ti6INNe6c@darkstar.UCSC.EDU> spencer@cats.ucsc.edu
(Michael Spencer) writes:

|> hrpctw@pnv.palm.cri.nz (Colin T. Wilson-Salt) writes:

|> >I can't seem to get the max() macro to work.  It works OK under C, but
|> >under C++ it gives me the error "Function 'max' should have a prototype".

What is the "max() macro"?  In the text you posted (not fully quoted
by your respondant), there is no such macro defined.  And you only
include standard headers, so it's not in the header.

C should implicitly define the function, as though it had a prototype.
This is one place where C++ differs, however; all functions must have
a prototype.

|> >Should I give up and write a replacement max() function/macro?

|> Roll your own. It's a lot easier than trying to figure out the
|> vagaries of compilers!  Try:

|> #define Minim(a,b)            ((a<b) ? a : b)
|> #define Maxim(a,b)            ((a>b) ? a : b)
|> #define InRange(a,lo,hi)      ((a<lo) ? 0 : ((a>hi) ? 0 : 1))
|> #define RangeSet(a,lo,hi)     ((a<lo) ? (a = lo) : (a>hi) ? (a = hi) : a )
|> #define CircleSet(a,lo,hi)    ((a<lo) ? (a = hi) : (a>hi) ? (a = lo) : a )

|> The last 3 will help avoid 'fence-post' errors.

The idea is good, but I don't like the implementation.  What happens
in the following case, for example:

	int			maxSoFar = INT_MIN ;
	int*			p = myTable ;
	for ( int i = tableLength ; i > 0 ; i -- )
		maxSoFar = Maxim( maxSoFar , *p ++ ) ;

You guessed it.  When p is larger than maxSoFar (which it will often
be at the beginning of the table), it gets incremented twice in the
loop.

BTW, I'm not recommending the above as good programming style.  But it
is typical of the way a lot of people write C.

The solution would be to replace all of the above functions with
inline's.  This way, the compiler guarantees that each parameter is
evaluated once and only once per call.
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung
Newsgroups: comp.lang.c++,comp.object
From: markmc@halcyon.com (Mark McWiggins)
Subject: Strong typing (was: Re: Pros and cons of C++)
Organization: Northwest Nexus Inc. (206) 455-3505
Date: Wed, 27 Jan 1993 08:27:21 GMT

samantha@shell.portal.com (Samantha Atkins) writes:

>Am I going askew here or is it as it seems to me that so called strong typing
>creates an untenable mess if you seriously attempt its use now and for the
>future?

Recompilation is an "untenable mess"? True, with CPUs even fast as they
are now and tools relatively dumb, you can do unnecessary recompilation.

But give me this any day over my customer calling from Buenos Aires
saying "What's this 'method not found' mean?" as in Smalltalk.

-- 
Mark McWiggins        Hermes & Associates		+1 206 632 1905 (voice)
markmc@halcyon.com    Box 31356, Seattle WA 98103-1356  +1 206 632 1738 (fax)
From: hendrik@vedge.com (Hendrik Boom)
Newsgroups: comp.lang.c++
Subject: Re: Safe version of C++
Date: 21 Jan 93 14:46:30 GMT
Organization: Visual Edge Software Ltd.

hlf@nic.cerf.net (Howard Ferguson) writes:
: I am wondering about overloading operators and const objects. 
: Do any of you netters have any opinions on these areas, or
: any other area of C++ which could be dropped to produce a 
: restricted version of the language for simplicity and safety.

Someone a few months ago posted an announcement that to their
great surprise, they managed to define a safe subset of C, so safe
that it could even be garbage collected reliably.  I believe they
had a technical report on the sublanguage available by anonymous FTP.
Unfortubately, I don't know where they are located; perhaps you
can find the post in the archives, wherever they may be.

I vagualy remember they might be in California. The name Berkeley comes
to mind.  Perhaps a phone call to computer science dept in Berkeley
would yield some leads.

Please let me know, by email or public posting, if anyone DEOS locate this
sublanguage.

	hendrik.
-- 
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work:	hendrik@vedge.com,  iros1!vedge!hendrik
at home:	uunet!ozrout!topoi!hendrik
From: rosen@cis.ohio-state.edu (jeffrey m rosen)
Newsgroups: comp.lang.c++
Subject: Borland C++ 3.1 for sale
Date: 26 Jan 93 05:34:39 GMT
Article-I.D.: eggplant.1k3lmfINN53k
Distribution: usa
Organization: The Ohio State University Dept. of Computer and Info. Science
NNTP-Posting-Host: eggplant.cis.ohio-state.edu


I have Borland C++ 3.1 for DOS/Windows for sale.  It is unregistered and
I have all of the manuals.  New this program sells for at least $375+tax
and I will make a great deal!  If interested leave email to 
rosen@cis.ohio-state.edu  Thanks,

Jeff Rosen
From: harvey@opl.com (Harvey Reed)
Newsgroups: comp.lang.c++
Subject: Re: C++ maintenance
Date: 26 Jan 93 00:50:29 GMT
Distribution: na

djb@geovision.gvc.com (Darren Burns) writes:


>...
>it does, but I'm not terribly familiar with the code.  In a member
>function I see:

>int the_class::do_something ( )
>{
>...
>    foo->xxx();
>...
>}

>Now, I'm browsing through this code and I'm thinking maybe the bug I'm
>looking for is in xxx().  I want to take a look at it.  In order to know
>which xxx to look at (since there may be many classes that have xxx), I
>need to know what class foo is.  But foo could be a global variable,
>a member of the_class, or a variable local to the function.  I have to
>hunt all over the place just to find out where to look for xxx.

>I find this a real pain.  I'm not experienced with C++, so maybe it's
>something you get used to.  I think that it's a general problem with
>...

Well, that can be a problem. One workaround for C++ (and maybe 
other languages) is to use naming conventions.

For example, our conventions require:

m<name>       (m)ember data of a class
s<name>       (s)tatic data of a class
a<name>       (a)ctual parameter to a method

and so on for data members. Other conventions for other names. In this
way, the name carries some context, so in a method you know:

m<name> and s<name> refers to members of the class that the method
belongs to, so you can look in that header. a<name> means you can
look in the signature for the method and see the type (class) there.

Short of using a naming convention, it is difficult to keep track
of what a name means. This may be where the experience level of
the author(s) come into play. Folks that have a lot of road time
with C++ tend to put some context in names.

I'm sure others have good suggestions in this area too! I'm looking
forward to see responses from your posting.





-- 
++harvey
===========================================================================
internet:       harvey@opl.com  /  hreed@cs.ulowell.edu  /  h.reed@ieee.org
voice/fax:      617-965-0220    /  617-965-7599
From: hlf@nic.cerf.net (Howard Ferguson)
Newsgroups: comp.lang.c++
Subject: Re: help with pass-by-reference
Date: 23 Jan 1993 02:15:34 GMT
Organization: CERFnet Dial n' CERF Customer Group
Distribution: usa
NNTP-Posting-Host: nic.cerf.net
Keywords: c++,reference,pass

In article <1993Jan22.231848.3690@nosc.mil> atkins@nosc.mil (Hugh T. Atkins) writes:
>Here's the setup, I have a class called Card and declare an array as
>follows
>
>
>Card myHand[5];  // this is an array of 5 playing cards
>
>I want to write a function which tests for pairs of cards and I want
>to use pass-by-reference but I can't figure out how to declare the
>function prototype.
>
>I'd like the function to return an int, something like this
>
>int hasPair( const Card& );
>
>

>if( hasPair( ?????? ) )
>  pairs++;
MAybe what you want is 
int hasPair ( const Card & *cardArray) {}

Because you can not move up an down the array with a reference i.e
references have no equivalent to pointer arithmatic.

But now that you are only passing a pointer so you might as well just
pass it by value. If you tried to write this as a reference to an 
array instead you would have the same effect because in C/C++ the 
name of an array is a pointer.

The bottom line is we should pass composite objects/structures/
aggregats/ any-thing-longer-than-a-couple-of-bytes as a reference,
but on the occations where more flexibility is required then a
pointer must be used. This is one of those cases.
with

if ( hasPair(myHand[0]))
but the first thing you are going to have to do with the card
is take the address of it inside the function. It is much cleaner
if the function takes a pointer and you can call it with

if (hasPair(myHand))

	hlf
You could of course just pass a reference to the first object,


From: peterj@PROBLEM_WITH_INEWS_GATEWAY_FILE (Peter Westley)
Date: Tue, 26 Jan 1993 01:45:54 GMT
Subject: BC++3.0/OWL DDEACK structure from WM_DDE_EXECUTE
Organization: HP Australasian Response Centre (Melbourne)
Newsgroups: comp.lang.c++
X-Newsreader: TIN [version 1.1 PL8.5]

[ Article crossposted from comp.os.ms-windows.programmer.misc ]
[ Author was Peter Westley ]
[ Posted on Tue, 26 Jan 1993 01:33:13 GMT ]

Is the DDEACK structure which comes pointed to in LOWORD of lParam when
WM_DDE_ACK is in response to a WM_DDE_EXECUTE message, valid?

Let me explain:

I have a method called when I receive a WM_DDE_ACK message:
(Using OWL dynamic dispatching it's easy) It get's called after sending a
WM_DDE_XXX message to the DDE serveer, when the server replies with an 
WM_DDE_ACK message.

class DDEClass
{
    //...
    WMDDEAck(TMessage & Msg)
	=[WM_FIRST + WM_DDE_ACK];
    WORD PendingMessage;
}

void DDEClass::WMDDEAck(TMessage& Msg)
{
    switch (PendingMessage)//pending message is the message which was just sent
			   //to the DDE server - i.e. it's what this WM_DDE_ACK
			   //is in reply to.
    {
	case WM_DDE_INITIATE:
	    //stuff
	    break;
        case WM_DDE_REQUEST:                       
	//I put this and the next case in blocks so that the DdeAck is only
	//created if it's needed (i.e. a local copy only)
	    {   //Get the pointer to the DDEACK     
		DDEACK *DdeAck = (DDEACK *)Msg.LP.Lo;
		if(DdeAck->fAck)               //\
		    //stuff if ack is valid;   // \
                else                           //  |- these are different to the
		    //other stuff if it isn't; // /   DDE_EXECUTE commands
	    }                                  ///
	    break;
	case WM_DDE_EXECUTE:
	    {   //Get the pointer to the DDEACK
		DDEACK *DdeAck = (DDEACK *)Msg.LP.Lo; 
		if(DdeAck->fAck)
		    //stuff if ack is valid;
                else
		    //other stuff if it isn't;
	    }
	    break;
    }
}

The problem is that when I get the response from the WM_DDE_REQUEST message,
everything is fine (same for the WM_DDE_INITIATE but I don't use the DDEACK
structure there)  When it enters the case WM_DDE_EXECUTE case section,
I get a GP fault on access to the DdeAck->fAck location.  The code generated
by the compiler is the same for both parts of the case statements (though
I haven't been able to check the code which sets up the DDEACK struct).

SO, does anyone know if there is a problem in the windows code (3.1) which 
might be broken here such that it doesn't allocate the DDEACK structure 
properly?  Is the DDEACK struct supposed to be valid when it's in response
to a WM_DDE_EXECUTE message?

Please help!

Thank in anticipation,

Peter Westley			 .-_!\		Hewlett Packard
Phone: +61 3 (T)272 2440        /     \		Australian Support Centre
Fax: +61 3 890 0326      	\_.-.b/<--------31-41 Joseph St.
E-mail: peterj@hparc0.aus.hp.com     v          Blackburn, Victoria 3130
//
// The views, opinions, information or other data here is solely from the
// mind of myself.  It is not the official word from my employer.  While I
// endeavour to provide accurate information, no responsibility is taken
// for errors or omissions.
Newsgroups: comp.lang.c++,comp.lang.smalltalk
From: pjl@cs.uiuc.edu (Paul Lucas)
Subject: Re: CLASS variable in C++ ?
Organization: University of Illinois at Urbana-Champaign
Date: Thu, 21 Jan 1993 19:13:18 GMT

In <1993Jan21.122335.62530@qut.edu.au> bub@qut.edu.au writes:

>	How to implement Class Variable and Class Method in C++?

	static

	For details, consult a C++ book; note C++ has no equivalent of
	class-instance variables found in Smalltalk.
-- 
	- Paul J. Lucas
	  AT&T Bell Laboratories
	  Naperville, IL
From: matt@centerline.com (Matt Landau)
Newsgroups: comp.lang.c++
Subject: Re: Result of delete operator applied to null pointer?
Date: 22 Jan 1993 17:33:35 GMT
Organization: CenterLine Software, Inc.
NNTP-Posting-Host: 140.239.1.32

In <1993Jan22.145654.10001@bradford.ac.uk> T.D.G.Sandford@bradford.ac.uk (TDG SANDFORD) writes:

>Is the effect of applying the delete operator to a null pointer defined?

Yes, the effect is defined.  Deleting a null pointer is supposed to
be safe (ARM, section 5.3.4).

Note that there is a bug in USL cfront 3.0.1 that causes "delete[] p"
to crash if p is NULL and p's destructor is virtual.  For this reason,
you might want to check for null pointers anyway, at least when using
delete[].
--
 Matt Landau			Waiting for a flash of enlightenment
 matt@centerline.com			  in all this blood and thunder
From: schmidt@rz.uni-passau.de (SCHMIDT GUIDO)
Newsgroups: comp.lang.c++
Subject: Re: Friend ..Overload Assignment opertr ..
Date: Sat, 23 Jan 1993 14:18:19 GMT
Organization: University of Passau - Germany
NNTP-Posting-Host: hiwi170.rz.uni-passau.de

In article <1993Jan22.075317.21062@usl.edu> rks9954@usl.edu (Srinivasa Rao K) writes:


> 


> Hi C++ masters,

>       I have small question ...

>       I am writing a "string"  class which i should be able
>       to use like


>       string str1;

>       str1 = "Hello world" ;



>       But We canot use a friend to overload the assignment oprator.

>      So finally  I had to convince myself to use something like


>       str1 <= "Hello world"


>       which works.

>      Is there any way to do the first method ....

>      
>      Thanks for those who spend time reading this ....




>Rao.

Hello!

operator=() is something like a constructor with built in destructor. You
can specify as many different constructors for one class as you like.
Likewise you can do for operator=().
So why not have:

	class String {
		public:
		...
		String& operator=( const String& aString ) { ... }
		String& operator=( char * aCharPtr ) { ... }
		String& operator=( const char aChar ) { ... }
		...
	};

I hope this will help you.

Guido.
--------------------------------------------------------------------
- Guido Schmidt                                                    -
- schmidt@rz.uni-passau.de                                         -
- Universitaet Passau, Germany                                     -
--------------------------------------------------------------------

Newsgroups: comp.lang.c++
From: gyme@uieea.ece.uiuc.edu (Jim Johnson)
Subject: Turbo C - Floats
Organization: University of Illinois at Urbana
Date: Thu, 28 Jan 1993 15:06:26 GMT

Sorry if this is a stupid question, but I just recently started
programming with Turbo C++ 3.0.

For some reason I am unable to do any floating point data storage with
the scanf function as follows:

float junk;
..........
..........
scanf("%f", &junk);
............
............

Whenever I try executing the program, I get an exit code of 3, the message
"Abnormal ... termination" and the message "Floating point ... not linked"

What's the problem?  I'm assuming it is probable something simple,
but you never know.

E-mail replies if possible please...

Jim Johnson

--
-------------------------------------------------------------------------------
James J. Johnson               |  "Never underestimate the power of human
a.k.a.  GYME                   |   stupidity."  -- Gyme
gyme@uieea.ece.uiuc.edu        |
From: marc@tanda.isis.org (Marc Thibault)
Newsgroups: comp.lang.c++
Subject: Re: build an array of * to functions
Date: Sat, 23 Jan 93 11:22:08 EST
Reply-To: marc@tanda.isis.org
Distribution: na
Organization: Thibault & Friends

In article <2514@itexjct.jct.ac.il> 
(Yoel Gurfinkel) writes: 
> But i don't know how to build an aray of 2 dimesions
>  sign + pointer to his function(with variables).

                thing (*fArray[size])(thing);

        - defines an array of "thing function(thing)" pointers. These
        can also be initialized as in:

        void (*funcPtrs[])(Cl) = {leaveF, showB, fxor, showM};

        where leaveF would be declared as "void leaveF(Cl)".

         By extension, it seems that a two-dimensional array could be
         defined as

                thing (*fArray[rows][cols])(thing);

         I haven't tried it but it seems the right thing to do.

        Cheers,
               Marc

---
 Marc Thibault        |  Automation Architect        |  All we are saying
 marc@tanda.isis.org  |  R.R.1, Oxford Mills,        |  is give global
 CIS:71441,2226       |  Ontario, Canada  K0G 1S0    |  warming a chance.
 NC FreeNet: aa185    |                              |

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.0

mQBNAiqxYTkAAAECALfeHYp0yC80s1ScFvJSpj5eSCAO+hihtneFrrn+vuEcSavh
AAUwpIUGyV2N8n+lFTPnnLc42Ms+c8PJUPYKVI8ABRG0I01hcmMgVGhpYmF1bHQg
PG1hcmNAdGFuZGEuaXNpcy5vcmc+
=HLnv
-----END PGP PUBLIC KEY BLOCK-----


Newsgroups: comp.lang.c++
From: nikki@trmphrst.demon.co.uk (Nikki Locke)
Subject: Re: Zortech
Reply-To: nikki@trmphrst.demon.co.uk
Distribution: world
X-Mailer: cppnews $Revision: 1.31 $
Organization: Trumphurst Ltd.
Date: Thu, 21 Jan 1993 20:28:33 +0000

In article <1993Jan20.143810.2935@netcom.com> erc@netcom.com (Eric Smith) writes:
> 
> What are the email addresses for Zortech?  (Technical support, marketing,
> etc.)

support@zortech.com ? For the others, ask postmaster@zortech.com.

> Is there a mailing list for Zortech info?

ztc-list@zortech.com. 

To subscribe, send a request to ztc-list-request@zortech.com.

[ I'm just a customer, nowadays ].
-- 
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++