virtual/real variable types

From: George Greer (greerga@circlemud.org)
Date: 12/04/01


I finally weeded out all of the "-1 = not-exist" cases for rooms, mobiles,
and objects by realizing that if I changed "room_vnum" and friends to
unsigned variables the compiler would helpfully point out all the cases for
me.  So now I'm left considering whether or not to keep them unsigned.

Argument for signed variables:
* Custom code assuming "-1" still works.

Unsigned rebuttal:
* The compiler (or at least GCC) points out bad cases for you while
  changing to unsigned variables. (Because "<0" on an unsigned variable is
  nonsensical.)

Argument for unsigned variables:
* No longer waste half of the integer space that could be used for rooms,
  mobiles, and objects. Maximum zone under the "100 rooms/zone" scheme
  would be 654 instead of 326.  Or 65,534 instead of 32,767 under bpl19
  scheme.

--
George Greer
greerga@circlemud.org

Index: structs.h
===================================================================
RCS file: /home/circledb/.cvs/circle/src/structs.h,v
retrieving revision 1.41
diff -u -p -r1.41 structs.h
--- structs.h   2001/11/27 06:42:22     1.41
+++ structs.h   2001/12/04 12:32:32
@@ -32,14 +32,18 @@
 /* preamble *************************************************************/

 /*
- * 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
+ * These should be either the smallest or largest possible value with
+ * your virtual/real data type.  For CircleMUD bpl20+'s 'ush_int', that
+ * is 65,535.  Note that room #0 is "The Void".
+ *
+ * This should probably just be "((1 << sizeof(room_vnum) * 8) - 1)".
+ *
+ * NOTE: If "sizeof(vnum) != sizeof(rnum)", you must make sure the
+ *       value below is valid in both variable types.
  */
-#define NOWHERE    (-1)    /* nil reference for room-database  */
-#define NOTHING           (-1)    /* nil reference for objects         */
-#define NOBODY    (-1)    /* nil reference for mobiles         */
+#define NOWHERE    (65535)     /* nil reference for room-database      */
+#define NOTHING           (65535)      /* nil reference for objects            */
+#define NOBODY    (65535)      /* nil reference for mobiles            */

 #define SPECIAL(name) \
    int (name)(struct char_data *ch, void *me, int cmd, char *argument)
@@ -527,18 +531,18 @@ typedef char                      byte;
 #endif

 /* Various virtual (human-reference) number types. */
-typedef sh_int room_vnum;
-typedef sh_int obj_vnum;
-typedef sh_int mob_vnum;
-typedef sh_int zone_vnum;
-typedef    int shop_vnum;
+typedef ush_int room_vnum;
+typedef ush_int obj_vnum;
+typedef ush_int mob_vnum;
+typedef ush_int zone_vnum;
+typedef     int shop_vnum;

 /* Various real (array-reference) number types. */
-typedef sh_int room_rnum;
-typedef sh_int obj_rnum;
-typedef sh_int mob_rnum;
-typedef sh_int zone_rnum;
-typedef    int shop_rnum;
+typedef ush_int room_rnum;
+typedef ush_int obj_rnum;
+typedef ush_int mob_rnum;
+typedef ush_int zone_rnum;
+typedef     int shop_rnum;


 /*

--
   +---------------------------------------------------------------+
   | 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 : 06/24/03 PDT