do_exits

Posted by Ithildin on Thu 18 Mar 2004 05:03 AM — 13 posts, 38,980 views.

USA #0
i'm porting over my exits snippet to smaugfuss. i get a warning from cygwin on it.



act_info.c: In function `do_exits':
act_info.c:1757: warning: suggest parentheses around && within ||


here's the code from that area. i tried puttin parenthesis in other places, but i'm just not getting it. i hvaen't slept much lately so that's probably it.


for ( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
    {
    if ( pexit->to_room
	  ||   IS_SET(pexit->exit_info, EX_CLOSED)
	  && (!IS_SET(pexit->exit_info, EX_WINDOW)
	  ||   IS_SET(pexit->exit_info, EX_ISDOOR))
	  &&  !IS_SET(pexit->exit_info, EX_HIDDEN) )
	{


any ideas?
USA #1
I think it's just trying to tell you to be "nice" about writing down the precedence.

That is:

a || b && c || d && e || f

should be written:

a || (b && c) || (d && e) || f
USA #2
here's the whole function if you need it.


void do_exits( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    EXIT_DATA *pexit;
    bool found;
    bool fAuto;

    set_char_color( AT_EXITS, ch );
    buf[0] = '\0';
    fAuto  = !str_cmp( argument, "auto" );

    if ( !check_blind(ch) )
	return;

    strcpy( buf, fAuto ? "&W&g[Exits:&W&g]" : "Obvious exits:\n\r&Y&g" );

    found = FALSE;
    for ( pexit = ch->in_room->first_exit; pexit; pexit = pexit->next )
    {
    if ( pexit->to_room	  
		||   IS_SET(pexit->exit_info, EX_CLOSED)	  
		&& (!IS_SET(pexit->exit_info, EX_WINDOW)	  
		||   IS_SET(pexit->exit_info, EX_ISDOOR))	  
there is line -->&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )
	{
	    found = TRUE;
	    if ( fAuto )
	    {
		//strcat( buf, " " );
		//strcat( buf, dir_name[pexit->vdir] );
	        if ( pexit->to_room
			
			  && IS_SET(pexit->exit_info, EX_CLOSED))
			{  strcat( buf, " &W&g-#&Y&c" );
		      strcat(buf, dir_name[pexit->vdir]);
			}
			else 
			{   strcat( buf, " &W&g-&Y&c" );
		        strcat( buf, dir_name[pexit->vdir] );
			}
		}
	    else
	    {
		sprintf( buf + strlen(buf), "%-5s - %s\n\r",
		    capitalize( dir_name[pexit->vdir] ),
		    room_is_dark( pexit->to_room )
			?  "Too dark to tell"
			: pexit->to_room->name
		    );
	    }
	}
    }
	
	

    if ( !found )
	strcat( buf, fAuto ? " none.\n\r" : "None.\n\r" );
    else
      if ( fAuto )
	strcat( buf, ".\n\r" );
    send_to_char( buf, ch );
    return;
}





USA #3
i'm sorry guys, this should be in coding. i wasn't paying attention.
USA #4
Right... it's probably asking you to do this:


		if ( pexit->to_room	  
		|| (  IS_SET(pexit->exit_info, EX_CLOSED)	  
		&& (!IS_SET(pexit->exit_info, EX_WINDOW) )
  
		|| (  IS_SET(pexit->exit_info, EX_ISDOOR))	  
                &&  !IS_SET(pexit->exit_info, EX_HIDDEN) ) )
USA #5
still got the same warning.
USA #6
Could you post the new offending code please? Just to be sure I have the "freshest" version. :)
USA #7

if 
( pexit->to_room 
|| 
(IS_SET(pexit->exit_info, EX_CLOSED) && !IS_SET(pexit->exit_info, EX_WINDOW))
||
(IS_SET(pexit->exit_info, EX_ISDOOR) && !IS_SET(pexit->exit_info, EX_HIDDEN))
)



Is what the code should look like to eliminate the warnings. Your original parenthesis were slightly off.

if 
( pexit->to_room
^1	  
||
IS_SET(pexit->exit_info, EX_CLOSED) && (!IS_SET(pexit->exit_info, EX_WINDOW)
      ^2                          ^2   ^3      ^4 (other 4 at end of line)
||
IS_SET(pexit->exit_info, EX_ISDOOR)  ) 
      ^5                          ^5 ^3
&&  
!IS_SET(pexit->exit_info, EX_HIDDEN)  )
       ^6                          ^6 ^1

Your third parenthetical set was throwing the whole check structure off and causing your warning.

(reformatted code so I could track paranthetical groupings more easily)
Amended on Thu 18 Mar 2004 11:03 AM by Meerclar
USA #8
Actually that's not right either, it doesn't follow the same logic... here is what seems to be the correct version...

(original)

	if ( pexit->to_room
	||   IS_SET(pexit->exit_info, EX_CLOSED)
	&& (!IS_SET(pexit->exit_info, EX_WINDOW)
	||   IS_SET(pexit->exit_info, EX_ISDOOR))
	&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )


(reformatted, but not changed)


	if ( 
	pexit->to_room
	||   IS_SET(pexit->exit_info, EX_CLOSED)
	&& (
		!IS_SET(pexit->exit_info, EX_WINDOW)
		||   IS_SET(pexit->exit_info, EX_ISDOOR)
	   )
	&&  !IS_SET(pexit->exit_info, EX_HIDDEN) )


Therefore, to keep the same precedence with parentheses...



	if ( 
	pexit->to_room
	|| (
		IS_SET(pexit->exit_info, EX_CLOSED)
		&& (
			!IS_SET(pexit->exit_info, EX_WINDOW)
			||   IS_SET(pexit->exit_info, EX_ISDOOR)
		   )
		&&  !IS_SET(pexit->exit_info, EX_HIDDEN)
	   )
	)


Don't you just love icky code... they really could have formatted things better to make this more clear.
USA #9
Better still would have been some comments so we know what he's actually trying to accomplish. I can't actually be sure if he's trying to check for closed windows and hidden doors (my edit) or just closed and hidden doors (Ksilyan's edit) or something else altogether. What the actual intent of the check is would determine the edit he needs to make to get rid of the warnings.
USA #10
You're right... it looks like the way you wrote it, seems more like what he *meant*... I just wrote out the parentheses to respect the same precedence that he *wrote*.

Do what I mean, not what I said, eh? :-) Too bad compilers don't work that way...

But you're definitely correct that some comments about intention would've solved a *bunch* of problems here.
USA #11
I'm sorry about not getting back to you guys. my internet started screwing up. couldn't get back on. plus it was late in the evening for me. i just woke up and i have to head out. but i'll be back later tonite. what my intent was to find if their was a door, and if there was, then it would put a # before the exit to show that it was closed. like this

[Exits: North #South}

south is a closed door. once you open it, the # goes away.

that same code worked without a problem on my smaug windows version. sorry for no elaboration. i'll be back later tonite, thanks for your help.

Ithildin
USA #12
i put in ksilyan's code. it worked beautifully. Thanks so much guys. i really appreciate the help.

Ithildin