What is the >>>= operator in C?

后端 未结 3 659
滥情空心
滥情空心 2021-01-29 17:03

Given by a colleague as a puzzle, I cannot figure out how this C program actually compiles and runs. What is this >>>= operator and the strange 1P1

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 17:36

    It is some rather obscure code involving digraphs, namely <: and :> which are alternative tokens for [ and ] respectively. There is also some use of the conditional operator. There is also a bit shifting operator, the right shift assignment >>=.

    This is a more readable version:

    while( a[ 0xFULL ? '\0' : -1 ] >>= a[ !!0X.1P1 ] )
    

    and an even more readable version, replacing the expressions in the [] for the values they resolve to:

    while( a[0] >>= a[1] )
    

    Replacing a[0] and a[1] for their values should make it easy to figure out what the loop is doing, i.e. the equivalent of:

    int i = 10;
    while( i >>= 1)
    

    which is simply performing (integer) division by 2 in each iteration, producing the sequence 5, 2, 1.

提交回复
热议问题