[FFmpeg-devel] & vs. &&

Benoit Fouet benoit.fouet
Mon Oct 12 14:21:06 CEST 2009


Hi,

I (well, gcc) have (has) seen some weirdness on the use of & vs. && in
our codebase:

first one:
libavformat/aviobuf.c:593: warning: suggest parentheses around operand
of ?!? or change ?&? to ?&&? or ?!? to ?~?
=========== ><8 ===========
int url_resetbuf(ByteIOContext *s, int flags)
{
    URLContext *h = s->opaque;
    if ((flags & URL_RDWR) || (h && h->flags != flags && !h->flags &
URL_RDWR))
        return AVERROR(EINVAL);
=========== 8>< ===========

I don't understand what the intent of the test is, but am quite sure it
is wrong, !h->flags & URL_RDWR being always false.
I'd naively think the correct way would be to remove the '!', but am not
sure.


second one:
libavcodec/vc1dec.c:2318: warning: suggest parentheses around operand of
?!? or change ?&? to ?&&? or ?!? to ?~?
=========== ><8 ===========
if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i];
=========== 8>< ===========

although this is the same functionnaly as '!is_intra[i] && is_coded[i]',
I find the latter more close to what we really want to test.

I'd suspect the second case should be fixed as suggested (i.e. '&' =>
'&&'), but would like to hear knowledgeable people for the first one.

Ben



More information about the ffmpeg-devel mailing list