Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Generally, looks good, but for 100% portability, replace that 8 with CHAR_BIT (or numeric_limits::max()) since it isn't guaranteed that characters are 8-bit.</p> <p>Any good compiler will be smart enough to merge all of the math constants at compile time.</p> <p>You can force it to be signed by using a type traits library. which would usually look something like (assuming your numeric_traits library is called numeric_traits):</p> <pre><code>typename numeric_traits&lt;T&gt;::signed_type x; </code></pre> <p>An example of a manually rolled numeric_traits header could look like this: <a href="http://rafb.net/p/Re7kq478.html" rel="noreferrer">http://rafb.net/p/Re7kq478.html</a> (there is plenty of room for additions, but you get the idea).</p> <p>or better yet, use boost:</p> <pre><code>typename boost::make_signed&lt;T&gt;::type x; </code></pre> <p>EDIT: IIRC, signed right shifts don't <strong>have to be</strong> arithmetic. It is common, and certainly the case with every compiler I've used. But I believe that the standard leaves it up the compiler whether right shifts are arithmetic or not on signed type. In my copy of the draft standard the following is written:</p> <blockquote> <p>The value of E1 >> E2 is E1 rightshifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 divided by the quantity 2 raised to the power E2. <strong>If E1 has a signed type and a negative value, the resulting value is implementation defined</strong>.</p> </blockquote> <p>But like I said, it will work on every compiler I've seen :-p.</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