Purpose of a function

Discussion in 'C' started by arun10427, Sep 28, 2010.

  1. arun10427

    arun10427 New Member

    Joined:
    Mar 4, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    Hello all,

    func(int* a, int b)
    {
    while((*a&(1 << b))==0);
    }

    Can someone tell me the hidden purpose of this code?
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Depending on the values of a and b it will execute.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    It will either do nothing (if *a & (1<<b) is zero) or hit an infinite loop (if *a & (1<<b) is non-zero).

    Best bet is to go after whoever wrote that code and give them a good LARTing, or at least ask them what the point of the function was, because they've almost certainly coded it wrong.

    *IF* the function is within a multithreaded program and some other thread is modifying *a, then it might be useful - it would wait until the b-th bit of *a is clear. But this is a terrible way of doing it because it uses 100% CPU until that is done.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice