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

  • Home
  • SEARCH
  • 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 6934433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:57:34+00:00 2026-05-27T11:57:34+00:00

I believe that during arithmetic overflow (in the context of an integer variable being

  • 0

I believe that during arithmetic overflow (in the context of an integer variable being assigned a value too large for it to hold), bits beyond the end of the variable could be overwritten.

But in the following C++11 program does this really still hold? I don’t know whether it’s UB, or disallowed, or implementation-specific or what, but when I take the variable past its maximum value, on a modern architecture, will I actually see arithmetic overflow of bits in memory? Or is that really more of a historical thing?

int main() {
   // (not unsigned; unsigned is defined to wrap-around)
   int x = std::numeric_limits<int>::max();
   x++;
}
  • 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-27T11:57:35+00:00Added an answer on May 27, 2026 at 11:57 am

    I don’t know whether it’s UB

    It is undefined, as specified in C++11 5/4:

    If during the evaluation of an expression, the result is not mathematically defined or not in the range of representable values for its type, the behavior is undefined.

    (As you say, it is defined for unsigned types, since they are defined by 3.9.1/4 to obey modular arithmetic)

    on a modern architecture, will I actually see arithmetic overflow of bits in memory?

    On all the modern architectures I know of (x86, ARM, 68000, and various DSPs), arithmetic is modular, with fixed-width 2s-complement results; on those architectures that can write the result to memory rather than registers, it will never overwrite more memory than the result size. For addition and subtraction, there is no difference to the CPU between signed and unsigned arithmetic. Overflow (signed or unsigned) can be detected from the state of CPU flags after the operation.

    I could imagine a compiler for, say, a 32-bit DSP that tried to implement arithmetic on 8 or 16-bit values packed into a larger word, where overflow would affect the rest of the word; however, all compilers I’ve seen for such architectures just defined char, short and int to be 32-bit types.

    Or is that really more of a historical thing?

    It would have happened on Babbage’s Difference Engine, since “memory” is a single number; if you partition it into smaller numbers, and don’t insert guard digits, then overflow from one will alter the value of the next. However, you couldn’t run any non-trivial C++ program on this architecture.

    Historically, I believe some processors would produce an exception on overflow – that would be why the behaviour is undefined.

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

Sidebar

Related Questions

I believe I understand that during macro expansion, a macro does not have access
I believe that Agile is nothing but another implementation of Spiral Model. I am
I believe that quantifying the productivity increase (extra working hours) is the most effective
I believe that IDictionary classes works better with sortable objects. I believe also that
I believe that I have successfully impersonated my own user account while running an
I'm lead to believe that I cannot count on the order of items added
Premise I believe that there is a way to objectively define "Good" and "Bad"
I am beginning to believe that unit testing high level, well-written code, which requires
I was lead to believe that MVC apps were BIN-deployable, so could be deployed
I can't believe that the following statement seems to be still true So, I

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.