Re: Who MOTD

From: George Greer (greerga@circlemud.org)
Date: 11/09/01


On Fri, 9 Nov 2001, Pj Bean wrote:

>Four infractions:
>>
>>1) Global variable will be for _everybody_, not just one person.  You want
>    the pointer in 'struct char_data' or 'struct descriptor_data'.
>>
>*cough* umm not exactly, He wants to define one GLOBAL whomessage for
>Everyone,
>He has it right Just he needs to use
>char whomessage;
>or
>char whomessage[50];

You're right.  I took:

  ... "&R[&r%s&R]&n\n", *whomessage);

to be for everybody due to the "[]" syntax.

>>2) You want 'whomessage', not '*whomessage'.  You're assigning a pointer,
>    not writing to what the pointer goes to.
>>
>Hes right on this one ...but he doesnt explain this quite well,

Pointers were the hardest part I had with C.  But that's probably because I
was determined enough to do it without any sort of formal training.  Just
the CircleMUD source code, the 'man' pages, and a compiler.  Those manual
pages are worth gold when you're unfamiliar with functions.  Took a long
time to be fluent though.  Memory corruption was a rude surprise too.

I'm also rather happy Jeremy didn't follow the GNU coding style and stuck
with K&R. :)

Don't try C before you know what's going on.  Most people can't just dive
in to the language.  I already had 6+ years of QuickBASIC [1] programming
by then anyway.  So I had functions, structures, switches, block if, and
everything necessary to adapt to C, except pointers.  A friend of mine who
wrote QuickBASIC code for 4 or so years (so he had at least some
programming experience) just couldn't handle C++ at all during the college
classes.

>>3) You need to allocate memory for that string.  'arg' is a magical global
>    buffer that is used for many different functions.
>>
>I've never had to ...but use buf instead, its usually already sizable enough
>for it.

If he intends to just:

  whomessage = arg;

then he'll have problems whenever something writes to one of the public
buffers[2].  Any time someone casts a spell in fact, because it eats all 4
buffers. ('arg' for targeting, 'buf*' for say_spelll)

Personally, I'd use either file_to_string_alloc() or the line editor to
write the messages.  That way you get more than one line and some minimal
formatting.

--
George Greer
greerga@circlemud.org

1: 1988.  I probably don't have the original floppy disks, not that I could
   read 5 1/4 inch disks now anyway.  Still have a copy of it on 3 1/2 inch
   disks with some of my old programs though... Hrmm.

2: Don't forget: arg, buf, buf1, and buf2 all die in '02.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST