Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6611631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:59:40+00:00 2026-05-25T19:59:40+00:00

My question is, within C++, is the following code defined? Some of it? And

  • 0

My question is, within C++, is the following code defined? Some of it? And if it is, what’s it supposed to do in these four scenarios?

word <<  100;
word >>  100;
word << -100;
word >> -100;

word is a uint32_t

(This is for a bottleneck in a 3d lighting renderer. One of the more minor improvements in the inner most loop I wanna make is eliminating needless conditional forks. One of those forks is checking to see if a left shift should be done on several 32 bit words as part of a hamming weight count. If the left shift accepts absurd values, the checks don’t need done at all)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:59:41+00:00Added an answer on May 25, 2026 at 7:59 pm

    In the C++0X draft N3290, §5.8:

    The behavior is undefined if the right operand is negative,
    or greater than or equal to the length in bits of the promoted left
    operand.

    Note: the above paragraph is identical in the C++03 standard.

    So the last two are undefined. The others, I believe depend on whether word is signed or not, if word is at least 101bits long. If word is “smaller” than 101bits, the above applies and the behavior is undefined.

    Here are the next two sections of that paragraph in C++0X (these do differ in C++03):

    The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are zero-filled. If E1 has an unsigned
    type, the value of the result is E1 × 2E2 , reduced modulo one more than the maximum value representable
    in the result type. Otherwise, if E1 has a signed type and non-negative value, and E1 × 2E2 is representable
    in the result type, then that is the resulting value; otherwise, the behavior is undefined.

    The value of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed
    type and a non-negative value, the value of the result is the integral part of the quotient of E1/2E2 . If E1
    has a signed type and a negative value, the resulting value is implementation-defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Follow-up question to this one . Basically, in the following code, why does the
This is more of a beginner's question. Say I have the following code: library(multicore)
This question is about organizing the actual CSS directives themselves within a .css file.
This is with reference to the below question: Execute program from within a C
Heads up: This is a weird question. I've got some really useful macros that
This question is more on javascript principle. function done(){ console.log('done defined with `function done(){
Within my Windows.Resources I have the following column defined: <DataGridTextColumn x:Key=CustomColumn x:Shared=False> <DataGridTextColumn.Header> <StackPanel>
I am using the Python code at the bottom of this question to send
In the following code snippet I've declared the variable id within the submit function.
Main question is: How to run the code within TestingButton_Click on several threads in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.