Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The two approaches are not quite the same thing, depending on the underlying data types. The standard (C11, 6.5.7 Bitwise shift operators) states that:</p> <blockquote> <p>If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.</p> </blockquote> <p>Hence, if you were to shift a 32-bit wide integer type 32 bits to the right, it would result in undefined behaviour. However, shifting it 31 bits and then another bit <em>is</em> well defined.</p> <p>That particular point, while a reason why someone may do this, is probably moot in this particular case. Given your type is <code>unsigned long long</code> (guaranteed 64 bits width), there should be no difference between <code>(x &gt;&gt; 31) &gt;&gt; 1</code> and <code>x &gt;&gt; 32</code>.</p> <p>However, if some platform actually defines <code>ext4_fsblk_t</code> as a 32-bit type (or if it's carried forward from an earlier implementation which allowed a 32-bit type <sup>(a)</sup>), you would find yourself having to resort to the two-stage shift to guarantee defined behaviour.</p> <hr> <p><sup>(a)</sup>: There was an interim stage between <code>ext3</code> and <code>ext4</code> which allowed <code>ext3</code> to move to 48 bits with its extents, a stepping stone on the way to <code>ext4</code> with its 64-bit data types. Prior to that, 8TB was the practical limit to file systems.</p> <p>It's <em>possible,</em> though I haven't confirmed, that this code snippet is a hangover from that transition, before the underlying data types went up to 64 bits wide.</p> <p>The type that came to be used, <code>sector_t</code>, was conditionally defined as either <code>u64</code> or <code>unsigned long</code>, which may explain why the code is there in the first place. In situations where it was defined as the latter, a two-stage shift may have been needed.</p> <p>However, given that <code>ext4</code> has left this interim stage behind, I'm not sure the two-stage shift is needed any more. Best bet is to raise a change request and see if it gets shot down by the developers :-)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload