Re: Circlemud design issues

From: George (greerga@CIRCLEMUD.ORG)
Date: 04/21/98

On Tue, 21 Apr 1998, James Turner wrote:

>George <greerga@CIRCLEMUD.ORG> writes:
>> But without going to C++, 'getName(ch) = NULL;' would not work as it does
>> now.  You'd either have to keep the macro, make a setName(), or use the
>> full structure.
>That kind of assignment _shouldn't_ work.  Lvalues are a nice effect
>of macros, but in general, using as such isn't the safest.

I believe you have worked in C++ too long.

You validate what you're writing, before you write it.

>of?  Can it be used on objects, rooms?  Also, other macros, such as
>GET_ALIASES(), work only on players and will segfault on mobs -- yet

It won't segfault on mobs.  That's what 'dummy_mob' is for.

>no checks are made.  Yes, it would be best to be careful when you use

Actually, the new CircleMUD macro will check for invalid player_special
use, not because it crashes (it doesn't), but because you can get strange
results from doing it.

#define CHECK_PLAYER_SPECIAL(ch, var) \
(((ch)->player_specials == &dummy_mob) ? \
(log("SYSERR: Mob using '"#var"' at %s:%d.", \
__FILE__, __LINE__), (var)) : (var))

Then a small change to the player specials:

-#define PRF_FLAGS(ch) ((ch)->player_specials->saved.pref)
+#define PRF_FLAGS(ch) CHECK_PLAYER_SPECIAL((ch),  \

Simple change, instant checking.  The CHECK_PLAYER_SPECIAL couldn't be done
with a function without ugly workarounds.

>Generally speaking, the more involved a piece of code is, the harder
>it is to turn into a macro.  More than that, the more involved it is,
>the less correct it is to use a macro.  CAN_SEE is a great example.
>Further, if you later chose to add checks to the code, or increase
>functionality, you wouldn't have any trouble doing so.

I didn't have any problem changing the checks in bpl13 to close a couple
loopholes in the code.

>assert() is a great way to catch errors in debug builds and not lose
>efficiency in production builds.

CircleMUD already uses it, but there aren't 'debug' and 'production'.

George Greer  -   | Genius may have its limitations, but stupidity | is not thus handicapped. -- Elbert Hubbard

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

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