NOWHERE, NOBODY, NOTHING tests...

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 03/05/01


A thought I just had about this comment in structs.h...

/*
 * Eventually we want to be able to redefine the below to any arbitrary
 * value.  This will allow us to use unsigned data types to get more
 * room and also remove the '< 0' checks all over that implicitly
 * assume these values. -gg 12/17/99
 */
#define NOWHERE    -1    /* nil reference for room-database     */
#define NOTHING    -1    /* nil reference for objects           */
#define NOBODY     -1    /* nil reference for mobiles           */

Most places where these values are tested do so to avoid crashing the
MUD by indexing an array with a negative value.  If, for some unknown
reason, the value being tested is not -1 but is another negative number
(for example, -2) than the '< 0' test would do what we really want while
the '== NO...' test will come back false and trick the MUD into thinking
that the value is good.  As a solution I would recommend creating macros
to do the tests which will for now test for '< 0' but if the data type
is changed to unsigned the macro which does the test can easily be
changed to '== NO...' at that time, something like this...

#define IS_NOWHERE(nr) ((nr) < 0)
#define IS_NOTHING(nr) ((nr) < 0)
#define IS_NOBODY(nr) ((nr) < 0)

Which could later be changed to...

#define IS_NOWHERE(nr) ((nr) == NOWHERE)
...

If you really want to get fancy (mutters about how nice a mudlogf()
would be for this)...

#define IS_NOWHERE(nr) ((nr) == NOWHERE ? TRUE : \
                        ((nr) >= 0 ? FALSE : \
                         log("%s: %d: SYSERR: %d passed to IS_NOWHERE().", \
                             __FILE__, __LINE__, (nr)), TRUE))

Regards, Peter

--
   +---------------------------------------------------------------+
   | 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/04/01 PST