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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:48:32+00:00 2026-06-06T15:48:32+00:00

I have a real world program that is similar to this one, which I’ll

  • 0

I have a real world program that is similar to this one, which I’ll call test.cpp:

#include <stdlib.h>

extern void f(size_t i);

int sample(size_t x)
{
     size_t a = x;
     size_t i;  

     for (i = a-2; i>=0; i--) {
           f(i);   
     }
}

And my problem is that i is an infinite loop.

If I run the following command:

g++ -S -o test.s test.cpp

I get the following assembly sequence:

        .file   "test.cpp"
        .text
        .globl  _Z6samplem
        .type   _Z6samplem, @function
_Z6samplem:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $32, %rsp
        movq    %rdi, -24(%rbp)
        movq    -24(%rbp), %rax
        movq    %rax, -8(%rbp)
        movq    -8(%rbp), %rax
        subq    $2, %rax
        movq    %rax, -16(%rbp)
.L2:
        movq    -16(%rbp), %rax
        movq    %rax, %rdi
        call    _Z1fm
        subq    $1, -16(%rbp)
        jmp     .L2
        .cfi_endproc
.LFE0:
        .size   _Z6samplem, .-_Z6samplem
        .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
        .section        .note.GNU-stack,"",@progbits

I’m no expert in assembly language, but I would expect to see code for the comparison i >= 0 and a conditional jump out of the loop. What’s going on here??

GNU C++ 4.6.3 on Ubuntu Linux

  • 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-06-06T15:48:34+00:00Added an answer on June 6, 2026 at 3:48 pm

    size_t is unsigned, so the condition i>=0 is always true. It is impossible for i to be negative.

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

Sidebar

Related Questions

NOTE: EDITED The real-world situation is a series of events that each have two
I've found similar questions but never the exact answer. I have Qt program that
I have a program that can generate video in real time. Now I would
So I have real time video stream. With 1 (one) person on It .
Let's say I have a program(C++, for example) that allocates multiple objects, never bigger
I have a program that simulates best-fit memory management. Basically, while there are available
I have command-line program that do a lot of work and produce a lot
I have a program that i have wrote, internally i am using the Fping
My friend have real Macintosh IIci, that uses Mac System 7.5.5 under a 68k
This problem came up in the real world, but I've translated it into a

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.