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 6792787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:00:51+00:00 2026-05-26T18:00:51+00:00

I just answered this question , which asked why iterating until 10 billion in

  • 0

I just answered this question, which asked why iterating until 10 billion in a for loop takes so much longer (the OP actually aborted it after 10 mins) than iterating until 1 billion:

for (i = 0; i < 10000000000; i++)

Now my and many others’ obvious answer was that it was due to the iteration variable being 32-bit (which never reaches 10 billion) and the loop getting an infinite loop.

But though I realized this problem, I still wonder what was really going on inside the compiler?

Since the literal was not appended with an L, it should IMHO be of type int, too, and therefore 32-bit. So due to overflow it should be a normal int inside the range to be reachable. To actually recognize that it cannot be reached from int, the compiler needs to know that it is 10 billion and therefore see it as a more-than-32-bit constant.

Does such a literal get promoted to a fitting (or at least implementation-defined) range (at least 64-bit, in this case) automatically, even if not appended an L and is this standard behaviour? Or is something different going on behind the scenes, like UB due to overflow (is integer overflow actually UB)? Some quotes from the Standard may be nice, if any.

Although the original question was C, I also appreciate C++ answers, if any different.

  • 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-26T18:00:51+00:00Added an answer on May 26, 2026 at 6:00 pm

    As far as C++ is concerned:

    C++11, [lex.icon] ¶2

    The type of an integer literal is the first of the corresponding list in Table 6 in which its value can be represented.

    And Table 6, for literals without suffixes and decimal constants, gives:

    int
    long int
    long long int
    

    (interestingly, for hexadecimal or octal constants also unsigned types are allowed – but each one come after the corresponding signed one in the list)

    So, it’s clear that in that case the constant has been interpreted as a long int (or long long int if long int was too 32 bit).

    Notice that “too big literals” should result in a compilation error:

    A program is ill-formed if one of its translation units contains an integer literal that cannot be represented by any of the allowed types.

    (ibidem, ¶3)

    which is promptly seen in this sample, that reminds us that ideone.com uses 32 bit compilers.


    I saw now that the question was about C… well, it’s more or less the same:

    C99, §6.4.4.1

    The type of an integer constant is the first of the corresponding list in which its value can be represented.

    list that is the same as in the C++ standard.


    Addendum: both C99 and C++11 allow also the literals to be of “extended integer types” (i.e. other implementation-specific integer types) if everything else fails. (C++11, [lex.icon] ¶3; C99, §6.4.4.1 ¶5 after the table)

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

Sidebar

Related Questions

This follows this prior question, which was answered. I actually discovered I could remove
A Java version of this question was just answered, and, well, I don't know
This is a follow up from a question of mine that was just answered
Update: Ehh -- Even though this question isn't answered, I've just emptied my pockets
I have seen this question answered a few times in which it is suggested
I started out with this question , which I sort of answered there ,
Earlier, I answered this question , which was basically about removing a table row.
I am sure this question has been asked and answered; but I haven't managed
I just answered a question where I said that while string interning is good
I know this question has been asked before and I read all the answers

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.