Re: [code] stuff

From: Christopher J. Dickey (cjd@esca.com)
Date: 10/25/96


On Fri, 25 Oct 1996, Mark Crichton wrote:

> I KNOW the advantages for C++ for this sort of work :)  I was going to try to
> avoid C++ since some of the people (including myself) don't have really strong
> C++ knowledge.

Good reason (=.

> Actually, my original idea was based (I think) off a Dr. Dobbs article about
> a C++ method of something Objective-C had, and that was functions that had
> many different parameter sets, and that ObjC took care of this automagically.
> (It went WELL beyond C++'s overloading....)

I looked into Objective-C, but I didn't really buy why you'd want to use
Objective-C over C++.

> (I also have the layout, also from Dr. Dobbs, for a C++ socket handler, so you
> can do:
> ch >> "Hello there" >>(Sock) 
> and it'll print "Hello there" to the ch socket.  Problem is that I dont think
> the socket clode is non-blocking *sigh*)

I do it more like

ch << "Hello there" << endl;

Pretty convenient and easy stuff, but really all a matter of semantics
(and some argue a little speedier than printf).  However, you can do
something similar in C with stdargs anyways, like this:

#include <stdarg.h>

char buf3[MAX_STRING_LENGTH];
void Send_to_char(struct char_data *ch, const char * const messg, ...)
{
  if (!ch->desc || !messg)
    return;

  va_list argptr;
  va_start(argptr, messg);
  vsprintf(buf3, messg, argptr);
  va_end(argptr);

  SEND_TO_Q(buf, ch->desc);
}

Now you have a send_to_char that works like printf so you can do:

Send_to_char(ch, "You see %d %s and a silly example!\r\n", num, str);

and pretty much use as many args as you'd like (well the limit is whatever
it is for printf).

This is also the way you'd want to set up a function to take a variable
amount of arguments as someone pointed out previously.

-cjd

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST