Problems compiling rom24b6(olc2.01+color1.2)

Posted by Yetro on Fri 15 Aug 2003 09:18 PM — 14 posts, 40,952 views.

#0
hi there...
here are the problems and warnings:

act_info.c: In function 'do_look':
act_info.c:1123: warning: suggest explicit braces to avoid ambiguous 'else'

pdesc = get_extra_descr( arg3, obj->extra_descr );
if ( pdesc != NULL )
if (++count == number)
{
send_to_char( pdesc, ch );
return;
}
else continue;

act_info.c:1132: warning: suggest explicit braces to avoid ambiguous 'else'

pdesc = get_extra_descr( arg3, obj->pIndexData->extra_descr );
if ( pdesc != NULL )
if (++count == number)
{
send_to_char( pdesc, ch );
return;
}
else continue;

act_obj.c: In function 'do_put':
act_info.c:424: warning: suggest explicit braces to avoid ambiguous 'else'

if (container->pIndexData->vnum == OBJ_VNUM_PIT
&& !CAN_WEAR(container,ITEM_TAKE))
if (obj->timer)
SET_BIT(obj->extra_flags,ITEM_HAD_TIMER);
else
obj->timer = number_range(100,200);

act_info.c:462: warning: suggest explicit braces to avoid ambiguous 'else'

if (container->pIndexData->vnum == OBJ_VNUM_PIT
&& !CAN_WEAR(obj, ITEM_TAKE) )
if (obj->timer)
SET_BIT(obj->extra_flags,ITEM_HAD_TIMER);
else
obj->timer = number_range(100,200);
obj_from_char( obj );
obj_to_obj( obj, container );

act_obj.c: In function 'get_cost':
act_obj.c:2496: warning: suggest explicit braces to avoid ambiguous 'else'

if (!IS_OBJ_STAT(obj,ITEM_SELL_EXTRACT))
for ( obj2 = keeper->carrying; obj2; obj2 = obj2->next_content )
{
if ( obj->pIndexData == obj2->pIndexData
&& !str_cmp(obj->short_descr,obj2->short_descr) )
if (IS_OBJ_STAT(obj2,ITEM_INVENTORY))
cost /= 2;
else
cost = cost * 3 / 4;
}

comm.c: In function 'process_output':
comm.c:1256: warning: suggest explicit braces to avoid ambiguous 'else'

if ( !merc_down )
if ( d->showstr_point )
write_to_buffer( d, "[Hit Return to continue]\n\r", 0 );
else if ( fPrompt && d->pString && d->connected == CON_PLAYING )
write_to_buffer( d, "> ", 2 );
else if ( fPrompt && d->connected == CON_PLAYING )
{

db.c: In function 'assign_area_vnum':
db.c:584: warning: suggest explicit braces to avoid ambiguous 'else'

void assign_area_vnum( int vnum )
{
if ( area_last->min_vnum == 0 || area_last->max_vnum == 0 )
area_last->min_vnum = area_last->max_vnum = vnum;
if ( vnum != URANGE( area_last->min_vnum, vnum, area_last->max_vnum ) )
if ( vnum < area_last->min_vnum )
area_last->min_vnum = vnum;
else
area_last->max_vnum = vnum;
return;
}

fight.c: In function 'one_hit':
fight.c:579: warning: suggest explicit braces to avoid ambiguous 'else'

if ( dt == gsn_backstab && wield != NULL)
if ( wield->value[0] != 2 )
dam *= 2 + (ch->level / 10);
else
dam *= 2 + (ch->level / 8);

handler.c: In function 'reset_char':
handler.c:521: warning: suggest explicit braces to avoid ambiguous 'else'

if (ch->pcdata->true_sex < 0 || ch->pcdata->true_sex > 2)
if (ch->sex > 0 && ch->sex < 3)
ch->pcdata->true_sex = ch->sex;
else
ch->pcdata->true_sex = 0;

handler.c: In function 'get_max_train':
handler.c:725: warning: suggest explicit braces to avoid ambiguous 'else'

if (class_table[ch->class].attr_prime == stat)
if (ch->race == race_lookup("human"))
max += 3;
else
max += 2;

return UMIN(max,25);

handler.c: In function 'unequip_char':
handler.c:1608: warning: suggest explicit braces to avoid ambiguous 'else'

if (!obj->enchanted)
for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
if ( paf->location == APPLY_SPELL_AFFECT )
{
for ( lpaf = ch->affected; lpaf != NULL; lpaf = lpaf_next )
{
lpaf_next = lpaf->next;
if ((lpaf->type == paf->type) &&
(lpaf->level == paf->level) &&
(lpaf->location == APPLY_SPELL_AFFECT))
{
affect_remove( ch, lpaf );
lpaf_next = NULL;
}

magic.c: In function 'obj_cast_spell':
magic.c:643: warning: suggest explicit braces to avoid ambiguous 'else'

if ( victim == NULL && obj == NULL)
if (ch->fighting != NULL)
victim = ch->fighting;
else
{
send_to_char("You can't do that.\n\r",ch);
return;
}

magic.c: In function 'spell_earthquake':
magic.c:2203: warning: suggest explicit braces to avoid ambiguous 'else'

if ( vch != ch && !is_safe_spell(ch,vch,TRUE))
if (IS_AFFECTED(vch,AFF_FLYING))
damage(ch,vch,0,sn,DAM_BASH,TRUE);
else
damage( ch,vch,level + dice(2, 8), sn, DAM_BASH,TRUE);
continue;
}

bit.c: In function 'flag_string':
bit.c:165: warning: operation on 'toggle' may be undefined

toggle = (++toggle) % 10;

buf[toggle][0] = '\0';

for (flag = 0; flag_table[flag].name != NULL; flag++)

screen.c: In function 'UpdateOLCScreen':
screen.c:658: warning: operation on 'i' may be undefined
screen.c:658: warning: operation on 'i' may be undefined

{
if ( d->screenmap[i] == d->oldscreenmap[i] )
{
i++;
continue;
}
sprintf(buf2, VT_CURSPOS "%c", i/80+1, i%80, d->screenmap[i++] );
strcat(buf, buf2);
j += strlen(buf2);
while ( d->screenmap && d->screenmap[i] != d->oldscreenmap[i] )
buf[j++] = d->screenmap[i++];
buf[j] = '\0';
}

hope you help me with these, greetings.
Australia Forum Administrator #1
Most of those problems - the ambiguous braces - can be fixed by adding some braces. eg. the first one:

if ( pdesc != NULL )
if (++count == number)
{
send_to_char( pdesc, ch );
return;
}
else continue;


Change it to:


if ( pdesc != NULL )
  {
  if (++count == number)
    {
    send_to_char( pdesc, ch );
    return;
    }
  else 
    continue;
  }


The braces remove the slight ambiguity about which "if" the "else" belongs to (in fact it is the closer one).



#2
Hi there and thanks for the tip, it worked and now i have just a few warning to get rid of.

I have just one doubt:
In act_obj.c

if (container->pIndexData->vnum == OBJ_VNUM_PIT
&& !CAN_WEAR(obj, ITEM_TAKE) )
if (obj->timer)
SET_BIT(obj->extra_flags,ITEM_HAD_TIMER);
else
obj->timer = number_range(100,200);
obj_from_char( obj );
obj_to_obj( obj, container );

i wonder if it should look like this:


if (container->pIndexData->vnum == OBJ_VNUM_PIT
&& !CAN_WEAR(obj, ITEM_TAKE) )
{
if (obj->timer)
SET_BIT(obj->extra_flags,ITEM_HAD_TIMER);
else
obj->timer = number_range(100,200);
}
obj_from_char( obj );
obj_to_obj( obj, container );

or like this:

if (container->pIndexData->vnum == OBJ_VNUM_PIT
&& !CAN_WEAR(obj, ITEM_TAKE) )
{
if (obj->timer)
SET_BIT(obj->extra_flags,ITEM_HAD_TIMER);
else
obj->timer = number_range(100,200);
obj_from_char( obj );
obj_to_obj( obj, container );
}

thats all greetings.
Australia Forum Administrator #3
In the absence of braces an "else" will only affect the very next statement - up to the semicolon - so your first example was correct.
#4
hi there, thank again for the info.
now i have a doubt with the first brace:

this ir the original code:

if (!obj->enchanted)
for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
if ( paf->location == APPLY_SPELL_AFFECT )
{
for ( lpaf = ch->affected; lpaf != NULL; lpaf = lpaf_next )
{
lpaf_next = lpaf->next;
if ((lpaf->type == paf->type) &&
(lpaf->level == paf->level) &&
(lpaf->location == APPLY_SPELL_AFFECT))
{
affect_remove( ch, lpaf );
lpaf_next = NULL;
}
}
}
else
{
affect_modify( ch, paf, FALSE );
affect_check(ch,paf->where,paf->bitvector);
}

this the fix: (my doubt is if i should put the first brace after the first "if line" or after the first "for line", i actually have it after the "for line")

if (!obj->enchanted)
for ( paf = obj->pIndexData->affected; paf != NULL; paf = paf->next )
{
if ( paf->location == APPLY_SPELL_AFFECT )
{
for ( lpaf = ch->affected; lpaf != NULL; lpaf = lpaf_next )
{
lpaf_next = lpaf->next;
if ((lpaf->type == paf->type) &&
(lpaf->level == paf->level) &&
(lpaf->location == APPLY_SPELL_AFFECT))
{
affect_remove( ch, lpaf );
lpaf_next = NULL;
}
}
}
else
{
affect_modify( ch, paf, FALSE );
affect_check(ch,paf->where,paf->bitvector);
}
}

I imagine that its ok.. but i just need confirmation.
Australia Forum Administrator #5
I think either would be equivalent. However after the "if" line makes it a bit clearer that the whole block of code depends on the "if".
#6
worked ok.

the warning remaining now (in stock rom2.4b6) are:

comm.c: In function 'main'
comm.c:421: warning: implicit declaration of function 'close'

#if defined(unix)
control = init_socket( port );
boot_db( );
sprintf( log_buf, "ROM is ready to rock on port %d.", port );
log_string( log_buf );
game_loop_unix( control );
close (control); /* this is line 421 */
#endif

comm.c: In function 'read_from_descriptor':
comm.c:1073: warning: implicit declaration of function 'read'

#if defined(MSDOS) || defined(unix)
for ( ; ; )
{
int nRead;

nRead = read( d->descriptor, d->inbuf + iStart, /*this is line 1073 */
sizeof(d->inbuf) - 10 - iStart );
if ( nRead > 0 )
{
iStart += nRead;
if ( d->inbuf[iStart-1] == '\n' || d->inbuf[iStart-1] == '\r' )
break;
}
else if ( nRead == 0 )
{
log_string( "EOF encountered on read." );
return FALSE;
}
else if ( errno == EWOULDBLOCK )
break;
else
{
perror( "Read_from_descriptor" );
return FALSE;
}
}
#endif

comm.c: In function 'write_to_descriptor'
comm.c:1538: warning: implicit declaration of function 'write'

#if defined(macintosh) || defined(MSDOS)
if ( desc == 0 )
desc = 1;
#endif

if ( length <= 0 )
length = strlen(txt);

for ( iStart = 0; iStart < length; iStart += nWrite )
{
nBlock = UMIN( length - iStart, 4096 );
if ( ( nWrite = write( desc, txt + iStart, nBlock ) ) < 0 )/*this is line 1538*/
{ perror( "Write_to_descriptor" ); return FALSE; }
}

return TRUE;
}

hope you can help with this..
on the oficial rom faq says this:

4.4.3 'Implicit declaration of function..'

You have tried to use a function that the compiler has no definition of. His can arise if you mistype the function name, haven't included a necessary header file, or simply haven't coded the function yet.
Australia Forum Administrator #7
You are missing the appropriate .h file, possible unistd.h.

Which operating system are you compiling it on?
#8
compiling (cygwin) and running on windows xp.
and in the src folder of the stock rom there isnt any unistd.h file.
#9
on rom2.4b6+olc2.1+colour1.2

i only have this warnings and above arent so i might find the fix in these code.

this warnings are:

bit.c: In function 'flag_string'
bit.c:165: warning: operation on 'toggle' may be undefined

/*****************************************************************************
Name: flag_string( table, flags/stat )
Purpose: Returns string with name(s) of the flags or stat entered.
Called by: act_olc.c, olc.c, and olc_save.c.
****************************************************************************/
char *flag_string( const struct flag_type *flag_table, long bits )
{
static char buf[10][MIL];
int flag;
static int toggle;

toggle = (++toggle) % 10;/*THIS IS LINE 165*/

buf[toggle][0] = '\0';

for (flag = 0; flag_table[flag].name != NULL; flag++)
{
if ( !is_stat( flag_table ) && IS_SET(bits, flag_table[flag].bit) )
{
strcat( buf[toggle], " " );
strcat( buf[toggle], flag_table[flag].name );
}
else
if ( flag_table[flag].bit == bits )
{
strcat( buf[toggle], " " );
strcat( buf[toggle], flag_table[flag].name );
break;
}
}

return (buf[toggle][0] != '\0') ? buf[toggle] + 1 : "none";
}

screen.c: In function 'UpdateOLCScreen'
screen.c:658: warning: operation on 'i' may be undefined
screen.c:658: warning: operation on 'i' may be undefined

// mandamos solo las diferencias
largo = strlen(d->screenmap);
i = j = 0;
buf[0] = '\0';
while(i<largo)
{
if ( d->screenmap[i] == d->oldscreenmap[i] )
{
i++;
continue;
}
sprintf(buf2, VT_CURSPOS "%c", i/80+1, i%80, d->screenmap[i++] );/*THIS LINE IS 658*/
strcat(buf, buf2);
j += strlen(buf2);
while ( d->screenmap && d->screenmap[i] != d->oldscreenmap[i] )
buf[j++] = d->screenmap[i++];
buf[j] = '\0';
}

write_to_buffer( d, buf, j );
write_to_buffer( d, VT_CURREST, 0 );
}

thats all
#10
The bugs from before are fixed.

the stock file is like this:
/* int read args( ( int fd, char *buf, int nbyte ) ); */

just have to this:

int read args( ( int fd, char *buf, int nbyte ) );

and done... dont know why there where ticket or whatever it says...
#11
Correcting the last post:

stock was: without the /* */
and to fix it: put /* */ on those lines
#12
Its not enough to solve the problem... but iam almost shure that its has something to do with it.
#13
you were right.. but wasnt specific enought for me.

add the follow line to comm.c and goodbye comm.c warnings.

#include <unistd.h> /* OLC -- for close read write etc */