Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Sep 1999 18:33:48 +1000
From:      Patryk Zadarnowski <patrykz@mycenae.ilion.eu.org>
To:        Gregory Bond <gnb@itga.com.au>
Cc:        hackers@FreeBSD.ORG
Subject:   Re: "style" question 
Message-ID:  <199909170833.SAA55426@mycenae.ilion.eu.org>
In-Reply-To: Your message of "Fri, 17 Sep 1999 18:21:35 %2B1000." <199909170821.SAA15276@lightning.itga.com.au> 

next in thread | previous in thread | raw e-mail | index | archive | help
> I'm looking at cleaning up a few compile nits and I'm wondering what the
> officially approved way of silencing "may not be used" warnings:
> 
> int
> foo(int flag)
> {
>         int j;
> 
>         if (flag) 
>                 j = 1;
> 
>         /* 
>          * This noop statement is enough to confuse the optimiser so it 
>          * forgets that j is initialised iff flag != 0 
>          */
>         flag = !!flag; 

I don't know about the "official"  way to silence the compiler (a well
placed  else statement  or a  "default" switch  case usually  does the
trick for  me) That is  to say, I'm  willing to argue that  fixing the
flow  of  control is  the  only  clean way  of  getting  rid of  these
warnings, unless  you know something special about  the allowed values
of  the offending variable  (eg.  you  know that  your switch  case is
exhaustive),  in which case  a dummy  "default" or  initializer cannot
hurt you much.

Also !!x IS NOT  a noop. For example, !!5 == 1.   I think you meant to
say `flag = ~~flag', which indeed is a NOP.

Pat.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199909170833.SAA55426>