A question about integers
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: A question about integers

  1. #1
    Join Date
    Jul 2010
    Posts
    75

    A question about integers

    Will
    Code:
    int i = 10000000;
    i++;
    take more time to process than
    Code:
    int i = 0;
    i++;
    ?

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,012

    Re: A question about integers

    No.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: A question about integers

    They will both compile down to
    Code:
    push 1000000
    inc [%%sp]
    and
    Code:
    push 0
    inc [%%sp]

  4. #4
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,290

    Re: A question about integers

    Quote Originally Posted by ninja9578 View Post
    They will both compile down to
    Code:
    push 1000000
    inc [%%sp]
    and
    Code:
    push 0
    inc [%%sp]
    or

    Code:
    push 1000001
    and
    Code:
    push 1
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: A question about integers

    IMO both your assembly variants are unlikely. The OP's code shows no reason to push the int at all because it's not going to be passed as a function parameter.

    I'd say discussing assembly details here is moot anyway and not really helpful to the OP...

    EDIT: Ok, I need to take back my statement about no need to push the int as the variable is just being constructed. Looks like I wrote the post too quickly. But the second paragraph still holds true IMO...
    Last edited by Eri523; March 3rd, 2011 at 08:07 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: A question about integers

    Quote Originally Posted by monarch_dodra View Post
    or

    Code:
    push 1000001
    and
    Code:
    push 1
    Probably not on -O0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center