Re: if(!(i%16))

Liste des GroupesRevenir à cl c  
Sujet : Re: if(!(i%16))
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 31. Mar 2024, 01:34:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uua7hj$19ih8$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 30/03/2024 22:49, fir wrote:
bart wrote:
On 30/03/2024 21:44, fir wrote:
  void bytes_dump_in_hex()
   {
     for(int i=0; i<bytes_size; i++)
     {
       if(!(i%16)) printf("\n");
>
       printf("%02x ", bytes[i]);
     }
   }
>
in the code above seem that those inner () in if(!(i%16)) are needed
>
why is that so?
>
Without them !i%16 will be parsed as (!i)%16.
>
and does it have sense?
It's a unary operator. Usually they are applied before binary ones. So '++ p + n' means '(++p)+n' not '++(p+n)' which wouldn't work anyway.
And -2-3 means (-2)-3 or -5, not -(2-3) which would be +1.
However whether it makes sense is beside the point. It's how C has always worked.

if ! is boolean operator and % is arithmetic then converting things to bolean and then do arithmetoc on it seems  not much reasonable...
Some people think that ! should work like that, so that here:
    not a<b and b<c
the 'not' applies to the entire expression: not(a<b and b<c), rather than (not a)<b and b<c.
But honestly, there are lots of things that are worse about C's set of precedences.

Date Sujet#  Auteur
30 Mar 24 * if(!(i%16))7fir
31 Mar 24 `* Re: if(!(i%16))6bart
31 Mar 24  `* Re: if(!(i%16))5fir
31 Mar 24   `* Re: if(!(i%16))4bart
31 Mar 24    `* Re: if(!(i%16))3fir
31 Mar 24     `* Re: if(!(i%16))2fir
31 Mar 24      `- Re: if(!(i%16))1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal