Re: ANSI C and GCC (argh+fix)

From: George (greerga@CIRCLEMUD.ORG)
Date: 06/02/98


On Tue, 2 Jun 1998, Jeremy Elson wrote:

>I'll try to fix this evening and post pl14 (or 13 take 2).

Hm, seems GCC doesn't care unless you specify -pedantic (which I wasn't).

Sigh, well, no one reported this previously. :P

The problem being, you cannot do:

  expression ? var1 : var2

so the correct (but usually ugly unless hidden by a macro as we are) fix
would be to change that to:

  *(expression ? &var1 : &var2)

That'll work in both the assignment and expression cases.

--- utils.h.old Tue Jun  2 19:35:26 1998
+++ utils.h     Tue Jun  2 19:37:42 1998
@@ -173,7 +173,7 @@

 /* Subtle bug, but works well for now. */
 #define CHECK_PLAYER_SPECIAL(ch, var) \
-       (((ch)->player_specials == &dummy_mob) ? (log("SYSERR: Mob using '"#var"' at %s:%d.", __FILE__, __LINE__), (var)) : (var))
+       (*(((ch)->player_specials == &dummy_mob) ? (log("SYSERR: Mob using '"#var"' at %s:%d.", __FILE__, __LINE__), &(var)) : &(var)))

 #define MOB_FLAGS(ch) ((ch)->char_specials.saved.act)
 #define PLR_FLAGS(ch) ((ch)->char_specials.saved.act)
@@ -292,7 +292,7 @@
 #define GET_LAST_TELL(ch)      CHECK_PLAYER_SPECIAL((ch), ((ch)->player_specials->last_tell))

 #define GET_SKILL(ch, i)       CHECK_PLAYER_SPECIAL((ch), ((ch)->player_specials->saved.skills[i]))
-#define SET_SKILL(ch, i, pct)  do { CHECK_PLAYER_SPECIAL((ch), (ch)->player_specials->saved.skills[i] = pct); } while(0)
+#define SET_SKILL(ch, i, pct)  do { CHECK_PLAYER_SPECIAL((ch), (ch)->player_specials->saved.skills[i]) = pct; } while(0)

 #define GET_EQ(ch, i)          ((ch)->equipment[i])

Sorry 'bout that.  Looks like I'll have to keep '-pedantic -ansi' on...

--
George Greer, greerga@circlemud.org | Genius may have its limitations, but
http://patches.van.ml.org/          | stupidity is not thus handicapped.
http://www.van.ml.org/CircleMUD/    |                  -- Elbert Hubbard


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



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