Re: errors typos and bugs

From: Edward Almasy (almasy@axis.com)
Date: 07/14/95


Leeman Strout writes:
> I forget who it was.. but on their report of a typo/bug/whatever  I went 
> through my db.c and found that indeed there was a SET_SKILL() without a 
> semicolon.. placing that semicolon there however made some very strange 
> errors pop up in gcc (-Wall)  This hasn't happened anywhere else, so I 
> was hoping that someone here could provide some enlightenment.  
> 
> 2350:  for (i = 1; i <= MAX_SKILLS; i++) {
> 2351:    if (GET_LEVEL(ch) < LVL_IMPL)
> 2352:      SET_SKILL(ch, i, 0);    <--- removing that semicolon fixes it
> 2353:    else
> 2354:      SET_SKILL(ch, i, 100);
> 2355:  }

That's because the SET_SKILL() has it's own {} pair when expanded,
so the semicolon is interpreted as a new statement, which ends the
if/else statement prematurely.  If you do this:
    for (i = 1; i <= MAX_SKILLS; i++) {
      if (GET_LEVEL(ch) < LVL_IMPL)
      {
        SET_SKILL(ch, i, 0);
      }
      else
        SET_SKILL(ch, i, 100);
    }
it will be fine.  (I recommend using {} pairs any time you have a
control block (for/if/while/do).  It often seems unnecessary, but
can save you lots of grief in debugging.)



 \_\_\_     _/ \_\_\_  axis data: specializing in online system setup & design
 \_  \_     _/ \_  \_    Edward Almasy                       almasy@axis.com  
 \_\_\_     _/ \_\_\_    President: Axis Data   Proprietor: NineJackNine BBS
     \_ _/  _/     \_    608-256-5732 (voice)            608-256-5697 (data)
 \_\_\_ _/_/_/ \_\_\_  9jack9: on the bleeding edges of culture and technology



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